set driver availabilities

This commit is contained in:
Maxime 2024-12-12 12:27:22 +01:00
parent 7a648ccd1b
commit 3ad5711ae7
1 changed files with 20 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package application
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"strconv" "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) resp, err := h.services.GRPC.MobilityAccounts.Register(context.TODO(), userRequest)
fmt.Println("resp : ", resp)
address := resp.Account.Data.GetFields()["address"].GetStructValue(); address := resp.Account.Data.GetFields()["address"].GetStructValue();
geometry := address.GetFields()["geometry"].GetStructValue(); geometry := address.GetFields()["geometry"].GetStructValue();
coordinates:= geometry.GetFields()["coordinates"].GetListValue(); coordinates:= geometry.GetFields()["coordinates"].GetListValue();
@ -192,6 +192,15 @@ func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Reques
radius = 0 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.DriverRegularAvailabilities {
DriverRequest : &solidarity_service.DriverRequest { DriverRequest : &solidarity_service.DriverRequest {
DriverAddress: &solidarity_service.Feature{ DriverAddress: &solidarity_service.Feature{
@ -222,13 +231,15 @@ func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Reques
Brand: r.PostFormValue("brand"), Brand: r.PostFormValue("brand"),
}, },
}, },
DriverAvailabilities: []*solidarity_service.RegularAvailabilitySlot{ DriverAvailabilities: []*solidarity_service.RegularAvailabilitySlot{},
{ }
DayOfWeek: 4,
StartTime: "10H00", for _, slot := range availabilities{
EndTime: "11H00", 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) 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) h.Renderer.CreateDriver(w, r)
} }