Bookings list in admin

This commit is contained in:
Arnaud Delcasse 2023-04-12 10:56:36 +02:00
parent ce8e30f999
commit bcddbc0d58
3 changed files with 77 additions and 0 deletions

View File

@ -447,6 +447,69 @@ func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Req
h.Renderer.AdminStatVehicles(w, r, vehicles, bookings, groups)
}
func (h ApplicationHandler) AdminStatBookings(w http.ResponseWriter, r *http.Request) {
vehicles := map[string]fleetsstorage.Vehicle{}
bookings := []fleetsstorage.Booking{}
reequest := &fleets.GetVehiclesRequest{
Namespaces: []string{"parcoursmob"},
}
reesp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), reequest)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiaries_ids := []string{}
for _, vehicle := range reesp.Vehicles {
v := vehicle.ToStorageType()
for _, b := range v.Bookings {
bookings = append(bookings, b)
beneficiaries_ids = append(beneficiaries_ids, b.Driver)
}
vehicles[v.ID] = v
}
groups := map[string]any{}
admingroups, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_organizations"},
})
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
for _, g := range admingroups.Groups {
groups[g.Id] = g.ToStorageType()
}
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
Accountids: beneficiaries_ids,
})
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiaries_map := map[string]any{}
for _, ben := range beneficiaries.Accounts {
beneficiaries_map[ben.Id] = ben.ToStorageType()
}
sort.Sort(sorting.BookingsByStartdate(bookings))
h.Renderer.AdminStatBookings(w, r, vehicles, bookings, groups, beneficiaries_map)
}
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
resp, err := h.services.GRPC.MobilityAccounts.GetAccounts(context.TODO(), &accounts.GetAccountsRequest{
Namespaces: []string{"parcoursmob"},

View File

@ -150,6 +150,7 @@ func main() {
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
//add statistiques
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
appAdmin.HandleFunc("/stats/bookings", applicationHandler.AdminStatBookings)
appAdmin.HandleFunc("/stats/beneficaires", applicationHandler.AdminStatBeneficaires)
appAdmin.HandleFunc("/stats/events", applicationHandler.AdminStatEvents)

View File

@ -99,3 +99,16 @@ func (renderer *Renderer) AdminStatVehicles(w http.ResponseWriter, r *http.Reque
renderer.Render("vehicles_state", w, r, files, state)
}
func (renderer *Renderer) AdminStatBookings(w http.ResponseWriter, r *http.Request, vehicles map[string]fleetsstorage.Vehicle, bookings []fleetsstorage.Booking, admingroups map[string]any, beneficiaries map[string]any) {
files := renderer.ThemeConfig.GetStringSlice("views.administration.bookings_list.files")
state := NewState(r, renderer.ThemeConfig, administrationMenu)
state.ViewState = map[string]any{
"vehicles_map": vehicles,
"bookings": bookings,
"admingroups": admingroups,
"beneficiaries_map": beneficiaries,
}
renderer.Render("bookings_stats", w, r, files, state)
}