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