list all bookings

This commit is contained in:
Maxime 2024-12-16 10:12:40 +01:00
parent 3ad5711ae7
commit 50e939c455
2 changed files with 25 additions and 13 deletions

View File

@ -128,17 +128,33 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
h.Renderer.SolidarityServiceBooking(w, r, booking) 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{}) accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{})
drivers, err := h.services.GRPC.SolidarityService.GetAllDrivers(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) parcourmobAccounts, err := h.beneficiaries(r)
if err != nil { if err != nil {
@ -148,10 +164,10 @@ func (h *ApplicationHandler) SolidarityService (w http.ResponseWriter, r *http.R
cacheid := uuid.NewString() cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) 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" { if r.Method== "POST" {

View File

@ -17,6 +17,7 @@ type SolidarityListState struct {
CacheId string `json:"cache_id"` CacheId string `json:"cache_id"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"` BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"` Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
Bookings *solidarity_service.GetAllBookingsSolidarityResponse `json:"bookings"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"` Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
} }
@ -27,6 +28,7 @@ type BeneficiariesSolidarityListState struct {
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"` BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"` Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
Drivers *solidarity_service.GetAllDriversResponse `json:"drivers"` 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() return s.JSON()
} }
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request) { 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.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) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files") files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu) state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = BeneficiariesSolidarityListState{ state.ViewState = BeneficiariesSolidarityListState{
@ -89,6 +84,7 @@ func (renderer *Renderer) BeneficiariesSolidarity(w http.ResponseWriter, r *http
Beneficiaries: parcourmobAccounts, Beneficiaries: parcourmobAccounts,
BeneficiariesSolidarity: accounts, BeneficiariesSolidarity: accounts,
Drivers: drivers, Drivers: drivers,
Bookings: bookings,
} }