From 5f12bed2d45a7d8ab9c289cb106de4413fc7d003 Mon Sep 17 00:00:00 2001 From: Arnaud Delcasse Date: Tue, 19 Nov 2024 15:53:40 +0100 Subject: [PATCH] Add beneficiaries informations to bookings list --- handlers/application/vehicles-management.go | 8 ++++++-- renderer/vehicle-management.go | 11 +++++++---- services/mobilityaccounts.go | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/handlers/application/vehicles-management.go b/handlers/application/vehicles-management.go index ebe1ea1..01156b9 100755 --- a/handlers/application/vehicles-management.go +++ b/handlers/application/vehicles-management.go @@ -61,9 +61,11 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r } } + driversMap, _ := h.services.GetBeneficiariesMap() + sort.Sort(sorting.VehiclesByLicencePlate(vehicles)) sort.Sort(sorting.BookingsByStartdate(bookings)) - h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings) + h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, driversMap, bookings) } func (h *ApplicationHandler) VehiclesManagementBookingsList(w http.ResponseWriter, r *http.Request) { @@ -98,7 +100,9 @@ func (h *ApplicationHandler) VehiclesManagementBookingsList(w http.ResponseWrite cacheid := uuid.NewString() h.cache.PutWithTTL(cacheid, bookings, 1*time.Hour) - h.Renderer.VehiclesManagementBookingsList(w, r, vehicles_map, bookings, cacheid) + driversMap, _ := h.services.GetBeneficiariesMap() + + h.Renderer.VehiclesManagementBookingsList(w, r, vehicles_map, driversMap, bookings, cacheid) } func (h *ApplicationHandler) VehiclesFleetAdd(w http.ResponseWriter, r *http.Request) { diff --git a/renderer/vehicle-management.go b/renderer/vehicle-management.go index eda9d35..6fa0768 100755 --- a/renderer/vehicle-management.go +++ b/renderer/vehicle-management.go @@ -5,28 +5,31 @@ import ( filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage" + mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" ) const vehiclesmanagementMenu = "vehicles_management" -func (renderer *Renderer) VehiclesManagementOverview(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle, vehicles_map map[string]fleetsstorage.Vehicle, bookings []fleetsstorage.Booking) { +func (renderer *Renderer) VehiclesManagementOverview(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle, vehicles_map map[string]fleetsstorage.Vehicle, driversMap map[string]mobilityaccountsstorage.Account, bookings []fleetsstorage.Booking) { files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.overview.files") state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state.ViewState = map[string]any{ "vehicles": vehicles, "bookings": bookings, "vehicles_map": vehicles_map, + "drivers_map": driversMap, } renderer.Render("fleet overview", w, r, files, state) } -func (renderer *Renderer) VehiclesManagementBookingsList(w http.ResponseWriter, r *http.Request, vehicles_map map[string]fleetsstorage.Vehicle, bookings []fleetsstorage.Booking, cacheid string) { +func (renderer *Renderer) VehiclesManagementBookingsList(w http.ResponseWriter, r *http.Request, vehiclesMap map[string]fleetsstorage.Vehicle, driversMap map[string]mobilityaccountsstorage.Account, bookings []fleetsstorage.Booking, cacheid string) { files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.bookings_list.files") state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state.ViewState = map[string]any{ "bookings": bookings, - "vehicles_map": vehicles_map, + "vehicles_map": vehiclesMap, + "drivers_map": driversMap, "cacheid": cacheid, } @@ -89,4 +92,4 @@ func (renderer *Renderer) UnbookingVehicle(w http.ResponseWriter, r *http.Reques renderer.Render("vehicule unbooking", w, r, files, state) -} \ No newline at end of file +} diff --git a/services/mobilityaccounts.go b/services/mobilityaccounts.go index b31ad04..8ead583 100755 --- a/services/mobilityaccounts.go +++ b/services/mobilityaccounts.go @@ -42,6 +42,22 @@ func (s *ServicesHandler) GetBeneficiaries() (accounts []storage.Account, err er return } +func (s *ServicesHandler) GetBeneficiariesMap() (accounts map[string]storage.Account, err error) { + accounts = map[string]storage.Account{} + request := &mobilityaccounts.GetAccountsRequest{ + Namespaces: []string{"parcoursmob_beneficiaries"}, + } + resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request) + + if err == nil { + for _, v := range resp.Accounts { + accounts[v.Id] = v.ToStorageType() + } + } + + return +} + func (s *ServicesHandler) GetAccounts() (accounts []storage.Account, err error) { accounts = []storage.Account{} request := &mobilityaccounts.GetAccountsRequest{