add onglet beneficiaries_silvermobi

This commit is contained in:
Maxime 2024-11-28 11:57:36 +01:00
parent 8f21248c29
commit 163ffefbfb
3 changed files with 37 additions and 29 deletions

View File

@ -8,6 +8,7 @@ import (
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
"github.com/google/uuid"
"github.com/gorilla/mux"
geojson "github.com/paulmach/go.geojson"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
@ -21,22 +22,11 @@ type Booking struct {
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(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)
if r.Method == "GET" && r.FormValue("date") != ""{
DepartureAddress := r.FormValue("departure");
DestinationAddress := r.FormValue("destination");
PickupDate := r.FormValue("date");
PassengerId := r.FormValue("passenger_id")
layout := "2006-01-02T15:04"
@ -95,7 +85,6 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
BookingData.bookingData = solidarity_service.CreateBookingSolidarityRequest {
Booking : &solidarity_service.BookingSolidarityRequest {
PassengerId: PassengerId,
DepartureAddress: &solidarity_service.Feature{
Lat: departuregeo.Geometry.Point[0],
Long: departuregeo.Geometry.Point[1],
@ -110,15 +99,18 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
},
}
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData, accounts, parcourmobAccounts, cacheid)
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData)
} else if r.Method == "POST" {
vars := mux.Vars(r)
beneficiaryID := vars["id"]
driverId := r.FormValue("driver_id")
id := uuid.New().String()
BookingData.bookingData.Booking.DriverId = driverId
BookingData.bookingData.Booking.PassengerId= beneficiaryID
BookingData.bookingData.Booking.Id = id
booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &BookingData.bookingData)
@ -129,11 +121,26 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
return
}
h.Renderer.SolidarityServiceBooking(w, r, booking, accounts, parcourmobAccounts)
h.Renderer.SolidarityServiceBooking(w, r, booking)
}else {
h.Renderer.SolidarityService(w, r, accounts, parcourmobAccounts, cacheid)
h.Renderer.SolidarityService(w, r)
}
}
func (h *ApplicationHandler) SolidarityService (w http.ResponseWriter, r *http.Request) {
accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(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.BeneficiariesSolidarity(w, r, accounts, parcourmobAccounts, cacheid)
}

View File

@ -138,7 +138,8 @@ func main() {
/*********************** CODE GROUP **************************/
//=================================silvermobi====================================
application.HandleFunc("/solidarity_service/", applicationHandler.DriversJourney)
application.HandleFunc("/solidarity_service/", applicationHandler.SolidarityService)
application.HandleFunc("/solidarity_service/create/{id}", applicationHandler.DriversJourney)
appGroup := application.PathPrefix("/group_module").Subrouter()
appGroup.HandleFunc("/", applicationHandler.Groups)

View File

@ -73,7 +73,14 @@ func (s SolidarityBookingsState) JSONWithLimits(a int, b int) template.JS {
return s.JSON()
}
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request) {
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, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = BeneficiariesSolidarityListState{
@ -87,28 +94,21 @@ func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Reque
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse,accounts *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = SolidarityBookingsState{
Bookings: bookings,
Beneficiaries: parcourmobAccounts,
BeneficiariesSolidarity: accounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest,accounts *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = SolidarityListState {
Count: len(parcourmobAccounts),
CacheId: cacheid,
Drivers: drivers,
Beneficiaries: parcourmobAccounts,
BeneficiariesSolidarity: accounts,
}
renderer.Render("solidarity_service", w, r, files, state)