diff --git a/handlers/application/beneficiaries.go b/handlers/application/beneficiaries.go index d649e29..707b3d7 100755 --- a/handlers/application/beneficiaries.go +++ b/handlers/application/beneficiaries.go @@ -30,8 +30,10 @@ import ( mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto" + "github.com/google/uuid" "github.com/gorilla/mux" + "google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/structpb" ) @@ -118,9 +120,17 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re sort.Sort(sorting.BeneficiariesByName(accounts)) + accountssolidarity, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{}) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusBadRequest) + return + } + cacheid := uuid.NewString() + h.cache.PutWithTTL(cacheid, accountssolidarity, 1*time.Hour) h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) - h.Renderer.BeneficiariesList(w, r, accounts, cacheid) + h.Renderer.BeneficiariesList(w, r, accounts,accountssolidarity, cacheid) } func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) { @@ -327,6 +337,39 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R organizations = append(organizations, o.ToStorageType()) } + beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types") + file_types_map := h.config.GetStringMapString("storage.files.file_types") + + h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list) +} + +func (h *ApplicationHandler) BeneficiarySolidarityDisplay(w http.ResponseWriter, r *http.Request) { + + accounts, err := h.beneficiaries(r) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusBadRequest) + return + } + + sort.Sort(sorting.BeneficiariesByName(accounts)) + + + vars := mux.Vars(r) + beneficiaryID := vars["beneficiaryid"] + + passenger := solidarity_service.GetPassengerRequest{ + Passenger: &solidarity_service.User{ + Id: beneficiaryID, + }, + } + + accountssolidarity, err := h.services.GRPC.SolidarityService.GetPassenger(context.TODO(), &passenger) + if err != nil { + fmt.Println(err) + w.WriteHeader(http.StatusBadRequest) + return + } solidarity_booking := &solidarity_service.GetBookingsByStatusRequest{ Status : 0, /// 0 : pending @@ -342,10 +385,13 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R return } - beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types") - file_types_map := h.config.GetStringMapString("storage.files.file_types") + cacheid := uuid.NewString() + h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour) + h.cache.PutWithTTL(cacheid, solidarity_bookings_list, 1*time.Hour) + + + h.Renderer.BeneficiarySolidarityDisplay(w, r ,accounts, accountssolidarity , solidarity_bookings_list, cacheid) - h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list, solidarity_bookings_list) } func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) { diff --git a/handlers/application/solidarity_service.go b/handlers/application/solidarity_service.go index 36e7415..34ec904 100644 --- a/handlers/application/solidarity_service.go +++ b/handlers/application/solidarity_service.go @@ -132,8 +132,6 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque BookingData.bookingData.Booking.DriverId = driverId BookingData.bookingData.Booking.Id = id - fmt.Println(BookingData.bookingData, "booking") - booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &BookingData.bookingData) if err != nil { diff --git a/main.go b/main.go index 2c8970d..e0c94b0 100755 --- a/main.go +++ b/main.go @@ -139,6 +139,8 @@ func main() { //=================================silvermobi==================================== application.HandleFunc("/solidarity_service/", applicationHandler.DriversJourney) + application.HandleFunc("/beneficiaries/solidarity_service/{beneficiaryid}", applicationHandler.BeneficiarySolidarityDisplay) + appGroup := application.PathPrefix("/group_module").Subrouter() appGroup.HandleFunc("/", applicationHandler.Groups) diff --git a/renderer/beneficiaries.go b/renderer/beneficiaries.go index f78f1c4..589e6f6 100755 --- a/renderer/beneficiaries.go +++ b/renderer/beneficiaries.go @@ -7,6 +7,7 @@ import ( fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" + solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto" ) @@ -16,6 +17,16 @@ type BeneficiariesListState struct { Count int `json:"count"` CacheId string `json:"cache_id"` Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"` + BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"` +} + +type BeneficiarySolidarityState struct { + Count int `json:"count"` + CacheId string `json:"cache_id"` + Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"` + BeneficiarySolidarity *solidarity_service.GetPassengerResponse `json:"beneficiarysolidarity"` + BookingSolidarity *solidarity_service.GetBookingsByStatusResponse `json:"bookingsolidarity"` + } func (s BeneficiariesListState) JSON() template.JS { @@ -30,7 +41,19 @@ func (s BeneficiariesListState) JSONWithLimits(a int, b int) template.JS { return s.JSON() } -func (renderer *Renderer) BeneficiariesList(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, cacheid string) { +func (s BeneficiarySolidarityState) JSON() template.JS { + result, _ := json.Marshal(s) + return template.JS(result) +} + +func (s BeneficiarySolidarityState) JSONWithLimits(a int, b int) template.JS { + if b < 5 { + s.Beneficiaries = s.Beneficiaries[a:b] + } + return s.JSON() +} + +func (renderer *Renderer) BeneficiariesList(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, accountssolidarity *solidarity_service.GetAllPassengersResponse, cacheid string) { files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.list.files") state := NewState(r, renderer.ThemeConfig, beneficiariesMenu) @@ -38,6 +61,7 @@ func (renderer *Renderer) BeneficiariesList(w http.ResponseWriter, r *http.Reque Count: len(accounts), CacheId: cacheid, Beneficiaries: accounts, + BeneficiariesSolidarity : accountssolidarity, } renderer.Render("beneficiaries_list", w, r, files, state) @@ -54,7 +78,7 @@ type BeneficiariesDisplayState struct { Beneficiary any } -func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []fleetsstorage.Booking, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any, event interface{}, solidarity_bookings_list interface{}) { +func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []fleetsstorage.Booking, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any, event interface{}) { files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files") state := NewState(r, renderer.ThemeConfig, beneficiariesMenu) state.ViewState = map[string]any{ @@ -65,7 +89,20 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ "documents": documents, "organizations": organizations, "event": event, - "solidarity_bookings": solidarity_bookings_list, + } + renderer.Render("beneficiaries_display", w, r, files, state) +} + +func (renderer *Renderer) BeneficiarySolidarityDisplay(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, beneficiary *solidarity_service.GetPassengerResponse, solidarity_bookings_list *solidarity_service.GetBookingsByStatusResponse, cacheid string) { + files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files") + state := NewState(r, renderer.ThemeConfig, beneficiariesMenu) + state.ViewState = BeneficiarySolidarityState{ + Count : len(accounts), + CacheId : cacheid, + Beneficiaries: accounts, + BeneficiarySolidarity : beneficiary, + BookingSolidarity : solidarity_bookings_list, + } renderer.Render("beneficiaries_display", w, r, files, state) } diff --git a/renderer/solidarity_service.go b/renderer/solidarity_service.go index e6763f1..01c0d86 100644 --- a/renderer/solidarity_service.go +++ b/renderer/solidarity_service.go @@ -59,6 +59,18 @@ func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS { return s.JSON() } +func (s SolidarityBookingsState) JSON() template.JS { + result, _ := json.Marshal(s) + return template.JS(result) +} + +func (s SolidarityBookingsState) JSONWithLimits(a int, b int) template.JS { + if b < 5 { + s.Beneficiaries = s.Beneficiaries[a:b] + } + return s.JSON() +} + func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) { files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files") state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)