From 50e939c455d473f981b1658806435bf979da44fd Mon Sep 17 00:00:00 2001 From: Maxime Date: Mon, 16 Dec 2024 10:12:40 +0100 Subject: [PATCH] list all bookings --- handlers/application/solidarity_service.go | 26 +++++++++++++++++----- renderer/solidarity_service.go | 12 ++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/handlers/application/solidarity_service.go b/handlers/application/solidarity_service.go index 315712b..c3e3ddf 100644 --- a/handlers/application/solidarity_service.go +++ b/handlers/application/solidarity_service.go @@ -128,17 +128,33 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque h.Renderer.SolidarityServiceBooking(w, r, booking) - }else { + }else { - h.Renderer.SolidarityService(w, r) + accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{}) + drivers, err := h.services.GRPC.SolidarityService.GetAllDrivers(context.TODO(), &emptypb.Empty{}) + bookings, err := h.services.GRPC.SolidarityService.GetAllBookingsSolidarity(context.TODO(), &emptypb.Empty{}) + + + parcourmobAccounts, err := h.beneficiaries(r) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusBadRequest) + } + cacheid := uuid.NewString() + h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) + + + h.Renderer.SolidarityService(w, r, accounts, drivers, parcourmobAccounts, bookings, cacheid) } } -func (h *ApplicationHandler) SolidarityService (w http.ResponseWriter, r *http.Request) { +func (h *ApplicationHandler) SolidarityService(w http.ResponseWriter, r *http.Request) { accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{}) drivers, err := h.services.GRPC.SolidarityService.GetAllDrivers(context.TODO(), &emptypb.Empty{}) + bookings, err := h.services.GRPC.SolidarityService.GetAllBookingsSolidarity(context.TODO(), &emptypb.Empty{}) + parcourmobAccounts, err := h.beneficiaries(r) if err != nil { @@ -148,10 +164,10 @@ func (h *ApplicationHandler) SolidarityService (w http.ResponseWriter, r *http.R cacheid := uuid.NewString() h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) - h.Renderer.BeneficiariesSolidarity(w, r, accounts, drivers, parcourmobAccounts, cacheid) + h.Renderer.SolidarityService(w, r, accounts, drivers, parcourmobAccounts, bookings ,cacheid) } -func (h *ApplicationHandler) CreateDriver (w http.ResponseWriter, r *http.Request) { +func (h *ApplicationHandler) CreateDriver(w http.ResponseWriter, r *http.Request) { if r.Method== "POST" { diff --git a/renderer/solidarity_service.go b/renderer/solidarity_service.go index 9120616..84bf61e 100644 --- a/renderer/solidarity_service.go +++ b/renderer/solidarity_service.go @@ -17,6 +17,7 @@ type SolidarityListState struct { CacheId string `json:"cache_id"` BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"` Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"` + Bookings *solidarity_service.GetAllBookingsSolidarityResponse `json:"bookings"` Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"` } @@ -27,6 +28,7 @@ type BeneficiariesSolidarityListState struct { BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"` Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"` Drivers *solidarity_service.GetAllDriversResponse `json:"drivers"` + Bookings *solidarity_service.GetAllBookingsSolidarityResponse `json:"bookings"` } @@ -73,14 +75,7 @@ func (s SolidarityBookingsState) JSONWithLimits(a int, b int) template.JS { return s.JSON() } -func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request) { - files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files") - state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu) - - renderer.Render("solidarity_service", w, r, files, state) -} - -func (renderer *Renderer) BeneficiariesSolidarity(w http.ResponseWriter, r *http.Request, accounts *solidarity_service.GetAllPassengersResponse, drivers *solidarity_service.GetAllDriversResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) { +func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts *solidarity_service.GetAllPassengersResponse, drivers *solidarity_service.GetAllDriversResponse, parcourmobAccounts []mobilityaccountsstorage.Account, bookings *solidarity_service.GetAllBookingsSolidarityResponse, cacheid string) { files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files") state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu) state.ViewState = BeneficiariesSolidarityListState{ @@ -89,6 +84,7 @@ func (renderer *Renderer) BeneficiariesSolidarity(w http.ResponseWriter, r *http Beneficiaries: parcourmobAccounts, BeneficiariesSolidarity: accounts, Drivers: drivers, + Bookings: bookings, }