From 127a3c44bf4ae20a5bef2602824c38cd9bd3f786 Mon Sep 17 00:00:00 2001 From: Maxime Date: Tue, 17 Sep 2024 14:42:27 +0200 Subject: [PATCH] createBooking --- handlers/application/solidarity_service.go | 61 ++++++++-------------- renderer/solidarity_service.go | 4 +- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/handlers/application/solidarity_service.go b/handlers/application/solidarity_service.go index 0732a65..7cd7179 100644 --- a/handlers/application/solidarity_service.go +++ b/handlers/application/solidarity_service.go @@ -12,7 +12,6 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) - func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) { accounts, err := h.beneficiaries(r) @@ -25,7 +24,10 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque cacheid := uuid.NewString() h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) - if r.Method == "POST" { + bookingData := solidarity_service.CreateBookingSolidarityRequest { + } + + if r.Method == "GET" { DepartureAddress := r.FormValue("departure"); DestinationAddress := r.FormValue("destination"); @@ -73,8 +75,11 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request) - booking := solidarity_service.BookingSolidarityRequest { - PassengerId: r.FormValue("account_id"), + bookingData = solidarity_service.CreateBookingSolidarityRequest { + Booking : &solidarity_service.BookingSolidarityRequest { + + PassengerId: r.FormValue("passenger_id"), + DriverId: r.FormValue("driver_id"), DepartureAddress: &solidarity_service.Feature{ Lat: departuregeo.Geometry.Point[0], Long: departuregeo.Geometry.Point[1], @@ -86,6 +91,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque Address: DepartureAddress, }, PickupDate : timestamp, + }, } if err != nil { @@ -94,49 +100,24 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque return } - h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, accounts, &booking, cacheid) + h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, accounts, &bookingData, cacheid) } else { h.Renderer.SolidarityService(w, r, accounts, cacheid) } + if r.Method == "POST" { -} + booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &bookingData) -// func (h *ApplicationHandler) CreatePendingBooking(w http.ResponseWriter, r *http.Request) { + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } -// if r.Method == "POST" { + h.Renderer.SolidarityServiceBooking(w, r, booking ) -// formvalue := solidarity_service.BookingSolidarityRequest{ -// PassengerId : "0", -// DriverId : "0", -// // Status : "0", -// DepartureAddress : booking.DepartureAddress, -// DestinationAddress : booking.DestinationAddress, -// PickupDate : booking.PickupDate, -// } + } -// request := &solidarity_service.BookingSolidarityRequest{ -// // Id -// PassengerId : formvalue.PassengerId, -// DriverId : formvalue.DriverId, -// //Status : formvalue.Status, -// DepartureAddress : booking.DepartureAddress, -// DestinationAddress : booking.DestinationAddress, -// PickupDate : formvalue.PickupDate, -// } - -// booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), request) - -// if err != nil { -// fmt.Println(err) -// w.WriteHeader(http.StatusInternalServerError) -// return -// } - -// h.Renderer.SolidarityServiceBooking(w, r , booking) - -// } - - -// } +} \ No newline at end of file diff --git a/renderer/solidarity_service.go b/renderer/solidarity_service.go index da0cc56..7173677 100644 --- a/renderer/solidarity_service.go +++ b/renderer/solidarity_service.go @@ -44,7 +44,7 @@ func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Reque renderer.Render("solidarity_service", w, r, files, state) } -func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, booking *solidarity_service.BookingSolidarityRequest) { +func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, booking *solidarity_service.CreateBookingSolidarityResponse) { files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files") state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu) state.ViewState = map[string]any{ @@ -54,7 +54,7 @@ func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *htt renderer.Render("solidarity_service", w, r, files, state) } -func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, accounts []mobilityaccountsstorage.Account, booking *solidarity_service.BookingSolidarityRequest, cacheid string) { +func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, accounts []mobilityaccountsstorage.Account, bookingData *solidarity_service.CreateBookingSolidarityRequest, cacheid string) { files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files") state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu) state.ViewState = SolidarityListState {