From 3ad5711ae73b70389c16f0280521541bf46483d6 Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 12 Dec 2024 12:27:22 +0100 Subject: [PATCH] set driver availabilities --- handlers/application/solidarity_service.go | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/handlers/application/solidarity_service.go b/handlers/application/solidarity_service.go index 292dc01..315712b 100644 --- a/handlers/application/solidarity_service.go +++ b/handlers/application/solidarity_service.go @@ -2,6 +2,7 @@ package application import ( "context" + "encoding/json" "fmt" "net/http" "strconv" @@ -177,7 +178,6 @@ func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Reques 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(); @@ -192,6 +192,15 @@ func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Reques radius = 0 } + availabilitiesJSON := r.PostFormValue("availabilities") + + var availabilities []solidarity_service.RegularAvailabilitySlot + + jsonerr:= json.Unmarshal([]byte(availabilitiesJSON), &availabilities) + if jsonerr != nil { + fmt.Printf("Erreur lors de la conversion de availabilitiesJSON : %v", err) + } + driverRequest := solidarity_service.DriverRegularAvailabilities { DriverRequest : &solidarity_service.DriverRequest { DriverAddress: &solidarity_service.Feature{ @@ -222,13 +231,15 @@ func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Reques Brand: r.PostFormValue("brand"), }, }, - DriverAvailabilities: []*solidarity_service.RegularAvailabilitySlot{ - { - DayOfWeek: 4, - StartTime: "10H00", - EndTime: "11H00", - }, - }, + DriverAvailabilities: []*solidarity_service.RegularAvailabilitySlot{}, + } + + for _, slot := range availabilities{ + driverRequest.DriverAvailabilities = append( driverRequest.DriverAvailabilities, &solidarity_service.RegularAvailabilitySlot{ + DayOfWeek: slot.DayOfWeek, + StartTime: slot.StartTime, + EndTime: slot.EndTime, + }) } driverResponse, err := h.services.GRPC.SolidarityService.SetDriverRegularAvailabilities(context.TODO(), &driverRequest) @@ -243,4 +254,4 @@ func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Reques h.Renderer.CreateDriver(w, r) -} +} \ No newline at end of file