create driver
This commit is contained in:
@@ -623,7 +623,7 @@ func parseBeneficiariesForm(r *http.Request) (map[string]any, error) {
|
||||
Email: r.PostFormValue("email"),
|
||||
Birthdate: date,
|
||||
PhoneNumber: r.PostFormValue("phone_number"),
|
||||
FileNumber: r.PostFormValue("file_number"),
|
||||
FileNumber: r.PostFormValue("file_number"),
|
||||
Gender: r.PostFormValue("gender"),
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,17 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
geojson "github.com/paulmach/go.geojson"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
@@ -148,7 +152,95 @@ func (h *ApplicationHandler) SolidarityService (w http.ResponseWriter, r *http.R
|
||||
|
||||
func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
|
||||
if r.Method== "POST" {
|
||||
|
||||
dataMap, err := parseBeneficiariesForm(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := structpb.NewValue(dataMap)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
userRequest := &mobilityaccounts.RegisterRequest{
|
||||
Account: &mobilityaccounts.Account{
|
||||
Namespace: "silvermobi",
|
||||
Data: data.GetStructValue(),
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.MobilityAccounts.Register(context.TODO(), userRequest)
|
||||
|
||||
fmt.Println("resp : ", resp)
|
||||
address := resp.Account.Data.GetFields()["address"].GetStructValue();
|
||||
geometry := address.GetFields()["geometry"].GetStructValue();
|
||||
coordinates:= geometry.GetFields()["coordinates"].GetListValue();
|
||||
if len(coordinates.GetValues()) < 2{
|
||||
fmt.Printf("Erreur lors de la récupération des coordonées : %v", err)
|
||||
return
|
||||
}
|
||||
radiusStr := r.PostFormValue("radius")
|
||||
radius, err := strconv.Atoi(radiusStr)
|
||||
if err != nil {
|
||||
fmt.Printf("Erreur lors de la conversion de radius : %v", err)
|
||||
radius = 0
|
||||
}
|
||||
|
||||
driverRequest := solidarity_service.DriverRegularAvailabilities {
|
||||
DriverRequest : &solidarity_service.DriverRequest {
|
||||
DriverAddress: &solidarity_service.Feature{
|
||||
Lat: coordinates.GetValues()[0].GetNumberValue(),
|
||||
Long: coordinates.GetValues()[1].GetNumberValue(),
|
||||
Address: "********",
|
||||
},
|
||||
DriverRadius: int32(radius),
|
||||
Driver: &solidarity_service.User{
|
||||
Id: resp.Account.Id,
|
||||
Alias: r.PostFormValue("alias"),
|
||||
FirstName: r.PostFormValue("first_name"),
|
||||
LastName: r.PostFormValue("last_name"),
|
||||
Grade: 1,
|
||||
Picture: "h.png",
|
||||
Gender: r.PostFormValue("gender"),
|
||||
VerifiedIdentity: true, ///////// a Modifier !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
},
|
||||
Preferences: &solidarity_service.Preferences{
|
||||
Smoking: false,
|
||||
Animals: false,
|
||||
Music: false,
|
||||
IsTalker: false,
|
||||
LuggageSize: 100,
|
||||
},
|
||||
Car: &solidarity_service.Car{
|
||||
Model: r.PostFormValue("model"),
|
||||
Brand: r.PostFormValue("brand"),
|
||||
},
|
||||
},
|
||||
DriverAvailabilities: []*solidarity_service.RegularAvailabilitySlot{
|
||||
{
|
||||
DayOfWeek: 4,
|
||||
StartTime: "10H00",
|
||||
EndTime: "11H00",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
driverResponse, err := h.services.GRPC.SolidarityService.SetDriverRegularAvailabilities(context.TODO(), &driverRequest)
|
||||
if err != nil {
|
||||
fmt.Printf("erreur lors de la création du conducteur: ", err)
|
||||
radius = 0
|
||||
}
|
||||
fmt.Println("driver: ", driverResponse)
|
||||
|
||||
|
||||
}
|
||||
|
||||
h.Renderer.CreateDriver(w, r)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user