Add Trajets Solidaire in Deplacement

This commit is contained in:
2024-11-22 17:26:32 +01:00
parent e811ea7a07
commit 8f21248c29
7 changed files with 164 additions and 26 deletions

View File

@@ -119,7 +119,6 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
sort.Sort(sorting.BeneficiariesByName(accounts))
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
h.Renderer.BeneficiariesList(w, r, accounts, cacheid)
@@ -332,6 +331,60 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types")
file_types_map := h.config.GetStringMapString("storage.files.file_types")
if r.Method == "POST" {
request := &mobilityaccounts.GetAccountRequest{
Id: beneficiaryID,
}
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
fields := resp.Account.Data.Fields
firstName, ok := fields["first_name"]
if !ok {
fmt.Println("first_name not found in the data")
w.WriteHeader(http.StatusInternalServerError)
return
}
lastName, ok := fields["last_name"]
if !ok {
fmt.Println("last_name not found in the data")
w.WriteHeader(http.StatusInternalServerError)
return
}
passenger := solidarity_service.PassengerTripRequest {
Passenger : &solidarity_service.User {
Id: resp.Account.Id,
FirstName: firstName.Kind.(*structpb.Value_StringValue).StringValue,
LastName: lastName.Kind.(*structpb.Value_StringValue).StringValue,
Alias: " ",
Grade: 0,
Picture: " ",
Gender: " ",
VerifiedIdentity: true,
},
}
silvermobiPassenger, err := h.services.GRPC.SolidarityService.SetPassengerTrip(context.TODO(), &passenger)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
t := silvermobiPassenger
t = t
}
solidarity_booking := &solidarity_service.GetBookingsByStatusRequest{
Status : 0, /// 0 : pending
UserId : beneficiaryID,
@@ -350,13 +403,11 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
var solidarity_bookings_list []any
for _, o := range solidarity_bookings_object.Booking {
fmt.Println(o)
if(o.PassengerPickupDate != nil){
solidarity_bookings_list = append(solidarity_bookings_list, o)
}
}
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list, solidarity_bookings_list)
}

View File

@@ -10,16 +10,20 @@ import (
"strings"
"time"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
models "git.coopgo.io/coopgo-apps/parcoursmob/utils/models"
"github.com/google/uuid"
"github.com/gorilla/mux"
geojson "github.com/paulmach/go.geojson"
//"gitlab.scity.coop/maas/navitia-golang"
//"gitlab.scity.coop/maas/navitia-golang/types"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -27,18 +31,22 @@ import (
var Depart any
var Arrive any
var SolidarityData models.SolidarityTransport
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
var (
//journeys_results *navitia.JourneyResults
carpool_results any
vehicle_results []any
driver_results []any
solidarity_results models.SolidarityTransport
)
vehiclech := make(chan []any, 1)
//navitiaCh := make(chan *navitia.JourneyResults, 1)
carpoolCh := make(chan any, 1)
solidarityCh := make(chan []any, 1)
solidarityCh := make(chan models.SolidarityTransport, 1)
locTime, errTime := time.LoadLocation("Europe/Paris")
if errTime != nil {
@@ -63,6 +71,7 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
carpoolresults any
vehicles = []any{}
drivers []any
accounts []any
)
if departuredate != "" && departuretime != "" && departure != "" && destination != "" {
@@ -174,6 +183,27 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
//solidarity-service
solidarityRequest := func() {
timestamp := timestamppb.New(departuredatetime)
PassengerId := r.FormValue("passenger_id")
driverId := r.FormValue("driver_id")
id := uuid.New().String()
type Booking struct {
bookingData solidarity_service.CreateBookingSolidarityRequest
}
var BookingData Booking
accountsRequest, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{})
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
}
for _, o := range accountsRequest.Passenger {
accounts = append(accounts, o)
}
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
request := solidarity_service.DriverJourneysRequest{
@@ -194,11 +224,56 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
}
for _, o := range driversRequest.DriverJourneys {
fmt.Println(o)
drivers = append(drivers, o)
}
solidarityCh <- drivers
if r.Method == "POST" {
BookingData.bookingData = solidarity_service.CreateBookingSolidarityRequest {
Booking : &solidarity_service.BookingSolidarityRequest {
Id: id,
DriverId: driverId,
PassengerId: PassengerId,
DepartureAddress: &solidarity_service.Feature{
Lat: departuregeo.Geometry.Point[0],
Long: departuregeo.Geometry.Point[1],
Address: departure,
},
DestinationAddress: &solidarity_service.Feature{
Lat: destinationgeo.Geometry.Point[0],
Long: destinationgeo.Geometry.Point[1],
Address: departure,
},
PickupDate : timestamp,
},
}
BookingData.bookingData.Booking.DriverId = driverId
BookingData.bookingData.Booking.Id = id
booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &BookingData.bookingData)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
booking = booking
SolidarityData = models.SolidarityTransport{
Drivers: drivers,
Beneficiaries: accounts,
}
}
SolidarityData = models.SolidarityTransport{
Drivers: drivers,
Beneficiaries: accounts,
}
solidarityCh <- SolidarityData
}
//go journeysRequest()
@@ -208,12 +283,12 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
carpool_results = <-carpoolCh
//journeys_results = <-navitiaCh
vehicle_results = <-vehiclech
driver_results = <-solidarityCh
solidarity_results = <-solidarityCh
}
h.Renderer.JourneysSearch(w, r, carpool_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime, driver_results) //journeys_results,
h.Renderer.JourneysSearch(w, r, carpool_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime, solidarity_results) //journeys_results,
}
type GroupsModule []groupstorage.Group

View File

@@ -9,6 +9,7 @@ import (
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
"github.com/google/uuid"
geojson "github.com/paulmach/go.geojson"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -20,15 +21,14 @@ 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)
return
}
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, parcourmobAccounts, 1*time.Hour)
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
if r.Method == "GET" && r.FormValue("date") != ""{
@@ -110,9 +110,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
},
}
fmt.Println(BookingData.bookingData, "booking")
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData, parcourmobAccounts, cacheid)
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData, accounts, parcourmobAccounts, cacheid)
} else if r.Method == "POST" {
@@ -131,11 +129,11 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
return
}
h.Renderer.SolidarityServiceBooking(w, r, booking, parcourmobAccounts)
h.Renderer.SolidarityServiceBooking(w, r, booking, accounts, parcourmobAccounts)
}else {
h.Renderer.SolidarityService(w, r, parcourmobAccounts, cacheid)
h.Renderer.SolidarityService(w, r, accounts, parcourmobAccounts, cacheid)
}
}