From de060b2ecf23d267a9537c60a5cf7a5cf5347d6a Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 19 Sep 2024 11:14:02 +0200 Subject: [PATCH] =?UTF-8?q?front=20module=20mobilit=C3=A9=20solidaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/application/solidarity_service.go | 46 +++++++++++++--------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/handlers/application/solidarity_service.go b/handlers/application/solidarity_service.go index 39e624e..9f08a0e 100644 --- a/handlers/application/solidarity_service.go +++ b/handlers/application/solidarity_service.go @@ -27,15 +27,26 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque bookingData := solidarity_service.CreateBookingSolidarityRequest { } - if r.Method == "GET" { + if r.Method != "GET" { DepartureAddress := r.FormValue("departure"); DestinationAddress := r.FormValue("destination"); PickupDate := r.FormValue("date"); + layout := "2006-01-02T15:04" + if PickupDate != "" { + fmt.Println("no date selected") + return + } dateParsed, err := time.Parse(layout, PickupDate) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + var ( departuregeo *geojson.Feature destinationgeo *geojson.Feature @@ -63,7 +74,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque } } - request := &solidarity_service.DriverJourneysRequest{ + request := solidarity_service.DriverJourneysRequest{ DepartureDate: timestamp, Departure: &solidarity_service.Feature{ Lat: departuregeo.Geometry.Point[0], @@ -72,8 +83,13 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque }, } - drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request) + drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), &request) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } bookingData = solidarity_service.CreateBookingSolidarityRequest { Booking : &solidarity_service.BookingSolidarityRequest { @@ -94,30 +110,24 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque }, } - if err != nil { - fmt.Println(err) - w.WriteHeader(http.StatusInternalServerError) - return - } - h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &bookingData, accounts, cacheid) } else { h.Renderer.SolidarityService(w, r, accounts, cacheid) } - // if r.Method == "POST" { + if r.Method == "POST" { - // booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &bookingData) + booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &bookingData) - // if err != nil { - // fmt.Println(err) - // w.WriteHeader(http.StatusInternalServerError) - // return - // } + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } - // h.Renderer.SolidarityServiceBooking(w, r, booking ) + h.Renderer.SolidarityServiceBooking(w, r, booking ) - // } + } } \ No newline at end of file