Les SilvermobiBeneficiaries deviennent des ParcourmobBEneficiaries
This commit is contained in:
@@ -33,7 +33,6 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
@@ -120,17 +119,10 @@ 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,accountssolidarity, cacheid)
|
||||
h.Renderer.BeneficiariesList(w, r, accounts, cacheid)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -340,52 +332,32 @@ 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")
|
||||
|
||||
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) {
|
||||
|
||||
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
|
||||
UserId : beneficiaryID,
|
||||
Type: 1, /// 1 : passenger
|
||||
}
|
||||
|
||||
solidarity_bookings_list, err := h.services.GRPC.SolidarityService.GetBookingsByStatus(context.TODO(), solidarity_booking)
|
||||
solidarity_bookings_object, err := h.services.GRPC.SolidarityService.GetBookingsByStatus(context.TODO(), solidarity_booking)
|
||||
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var bookings []any
|
||||
|
||||
for _, o := range solidarity_bookings_list.Booking {
|
||||
if(o.PickupDate != nil){
|
||||
bookings = append(bookings, o)
|
||||
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.BeneficiarySolidarityDisplay(w, r , accountssolidarity , bookings)
|
||||
|
||||
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) {
|
||||
|
||||
@@ -10,6 +10,7 @@ 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"
|
||||
@@ -17,9 +18,10 @@ import (
|
||||
"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"
|
||||
//"gitlab.scity.coop/maas/navitia-golang"
|
||||
//"gitlab.scity.coop/maas/navitia-golang/types"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
var Depart any
|
||||
@@ -28,13 +30,16 @@ var Arrive any
|
||||
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
var (
|
||||
journeys_results *navitia.JourneyResults
|
||||
//journeys_results *navitia.JourneyResults
|
||||
carpool_results any
|
||||
vehicle_results []any
|
||||
driver_results []any
|
||||
)
|
||||
vehiclech := make(chan []any, 1)
|
||||
navitiaCh := make(chan *navitia.JourneyResults, 1)
|
||||
//navitiaCh := make(chan *navitia.JourneyResults, 1)
|
||||
carpoolCh := make(chan any, 1)
|
||||
solidarityCh := make(chan []any, 1)
|
||||
|
||||
locTime, errTime := time.LoadLocation("Europe/Paris")
|
||||
if errTime != nil {
|
||||
fmt.Println("Loading timezone location Europe/Paris error : ")
|
||||
@@ -54,9 +59,10 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||
var (
|
||||
departuregeo *geojson.Feature
|
||||
destinationgeo *geojson.Feature
|
||||
journeys *navitia.JourneyResults
|
||||
//journeys *navitia.JourneyResults
|
||||
carpoolresults any
|
||||
vehicles = []any{}
|
||||
drivers []any
|
||||
)
|
||||
|
||||
if departuredate != "" && departuretime != "" && departure != "" && destination != "" {
|
||||
@@ -78,35 +84,35 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
journeysRequest := func() {
|
||||
//TODO make it a library
|
||||
session, _ := navitia.NewCustom(
|
||||
h.config.GetString("services.navitia.api_key"),
|
||||
"https://api.navitia.io/v1",
|
||||
&http.Client{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
navitiaCh <- nil
|
||||
return
|
||||
}
|
||||
// journeysRequest := func() {
|
||||
// //TODO make it a library
|
||||
// session, _ := navitia.NewCustom(
|
||||
// h.config.GetString("services.navitia.api_key"),
|
||||
// "https://api.navitia.io/v1",
|
||||
// &http.Client{})
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusBadRequest)
|
||||
// navitiaCh <- nil
|
||||
// return
|
||||
// }
|
||||
|
||||
request := navitia.JourneyRequest{
|
||||
From: types.ID(fmt.Sprintf("%f", departuregeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", departuregeo.Geometry.Point[1])),
|
||||
To: types.ID(fmt.Sprintf("%f", destinationgeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", destinationgeo.Geometry.Point[1])),
|
||||
Date: departuredatetime.Add(-2 * time.Hour),
|
||||
DateIsArrival: false, //TODO
|
||||
}
|
||||
// request := navitia.JourneyRequest{
|
||||
// From: types.ID(fmt.Sprintf("%f", departuregeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", departuregeo.Geometry.Point[1])),
|
||||
// To: types.ID(fmt.Sprintf("%f", destinationgeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", destinationgeo.Geometry.Point[1])),
|
||||
// Date: departuredatetime.Add(-2 * time.Hour),
|
||||
// DateIsArrival: false, //TODO
|
||||
// }
|
||||
|
||||
journeys, err = session.Journeys(context.Background(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusBadRequest)
|
||||
// return
|
||||
}
|
||||
navitiaCh <- journeys
|
||||
// journeys, err = session.Journeys(context.Background(), request)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// // w.WriteHeader(http.StatusBadRequest)
|
||||
// // return
|
||||
// }
|
||||
// navitiaCh <- journeys
|
||||
|
||||
}
|
||||
// }
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CARPOOL
|
||||
carpoolRequest := func() {
|
||||
@@ -163,15 +169,51 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
vehiclech <- vehicles
|
||||
}
|
||||
go journeysRequest()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////:::
|
||||
//solidarity-service
|
||||
solidarityRequest := func() {
|
||||
timestamp := timestamppb.New(departuredatetime)
|
||||
|
||||
|
||||
request := solidarity_service.DriverJourneysRequest{
|
||||
DepartureDate: timestamp,
|
||||
Departure: &solidarity_service.Feature{
|
||||
Lat: departuregeo.Geometry.Point[0],
|
||||
Long: departuregeo.Geometry.Point[1],
|
||||
Address: departure,
|
||||
},
|
||||
}
|
||||
|
||||
driversRequest, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), &request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, o := range driversRequest.DriverJourneys {
|
||||
fmt.Println(o)
|
||||
drivers = append(drivers, o)
|
||||
}
|
||||
|
||||
solidarityCh <- drivers
|
||||
|
||||
}
|
||||
//go journeysRequest()
|
||||
go carpoolRequest()
|
||||
go vehicleRequest()
|
||||
go solidarityRequest()
|
||||
carpool_results = <-carpoolCh
|
||||
journeys_results = <-navitiaCh
|
||||
//journeys_results = <-navitiaCh
|
||||
vehicle_results = <-vehiclech
|
||||
}
|
||||
driver_results = <-solidarityCh
|
||||
|
||||
h.Renderer.JourneysSearch(w, r, carpool_results, journeys_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime)
|
||||
}
|
||||
|
||||
|
||||
h.Renderer.JourneysSearch(w, r, carpool_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime, driver_results) //journeys_results,
|
||||
}
|
||||
|
||||
type GroupsModule []groupstorage.Group
|
||||
|
||||
@@ -9,7 +9,6 @@ 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"
|
||||
)
|
||||
|
||||
@@ -28,15 +27,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
accounts, 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, accounts, 1*time.Hour)
|
||||
h.cache.PutWithTTL(cacheid, parcourmobAccounts, 1*time.Hour)
|
||||
|
||||
|
||||
@@ -121,7 +112,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
fmt.Println(BookingData.bookingData, "booking")
|
||||
|
||||
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData, accounts, parcourmobAccounts, cacheid)
|
||||
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData, parcourmobAccounts, cacheid)
|
||||
|
||||
} else if r.Method == "POST" {
|
||||
|
||||
@@ -144,7 +135,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
}else {
|
||||
|
||||
h.Renderer.SolidarityService(w, r, accounts, parcourmobAccounts, cacheid)
|
||||
h.Renderer.SolidarityService(w, r, parcourmobAccounts, cacheid)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user