add onglet beneficiaries_silvermobi

This commit is contained in:
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)
}