From 9965271788d353576392c5fac2af84d50507e594 Mon Sep 17 00:00:00 2001 From: soukainna Date: Wed, 22 Feb 2023 11:01:29 +0100 Subject: [PATCH] add event list in statistique page --- handlers/application/administration.go | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/handlers/application/administration.go b/handlers/application/administration.go index 7c38415..052d8cb 100644 --- a/handlers/application/administration.go +++ b/handlers/application/administration.go @@ -11,6 +11,8 @@ import ( "time" "git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting" + agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi" + agendastorage "git.coopgo.io/coopgo-platform/agenda/storage" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" "git.coopgo.io/coopgo-platform/fleets/storage" groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi" @@ -20,6 +22,7 @@ import ( "github.com/google/uuid" "github.com/gorilla/mux" "google.golang.org/protobuf/types/known/structpb" + "google.golang.org/protobuf/types/known/timestamppb" ) func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) { @@ -64,8 +67,40 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque } sort.Sort(sorting.GroupsByName(groups)) + ////////////////////////////////////add event//////////////////////////////////////////// + rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{ + Namespaces: []string{"parcoursmob_dispositifs"}, + Mindate: timestamppb.New(time.Now().Add(-24 * time.Hour)), + }) - h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + responses := []agendastorage.Event{} + + groupids := []string{} + for _, e := range rresp.Events { + groupids = append(groupids, e.Owners...) + responses = append(responses, e.ToStorageType()) + } + + sort.Sort(sorting.EventsByStartdate(responses)) + + groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{ + Groupids: groupids, + }) + groupps := map[string]any{} + + if err == nil { + for _, g := range groupsresp.Groups { + groupps[g.Id] = g.ToStorageType() + } + } + ///////////////////////////////////////////////////////////////////////////////////////// + h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings, responses) } func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) { @@ -354,7 +389,8 @@ func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Req vehicles, _ := h.services.GetVehiclesMap() groups, _ := h.services.GetGroupsMap() - + // fmt.Println(vehicles) + // fmt.Println("////////////////////////////////////////:") h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups) }