Add Trajets Solidaire in Deplacement
This commit is contained in:
parent
e811ea7a07
commit
8f21248c29
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,10 @@ import (
|
|||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
models "git.coopgo.io/coopgo-apps/parcoursmob/utils/models"
|
||||
|
||||
)
|
||||
|
||||
const journeysMenu = "journeys"
|
||||
|
@ -23,6 +24,7 @@ type BeneficiariesCovoiturageA struct {
|
|||
Beneficiaries []any `json:"beneficiaries"`
|
||||
}
|
||||
|
||||
|
||||
func (s BeneficiariesCovoiturage) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
|
@ -35,7 +37,7 @@ func (s BeneficiariesCovoiturage) JSONWithLimits(a int, b int) template.JS {
|
|||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string, drivers []any) { //transitjourneys any,
|
||||
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string, solidarity_results models.SolidarityTransport ) { //transitjourneys any,
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files")
|
||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||
state.ViewState = map[string]any{
|
||||
|
@ -47,7 +49,7 @@ func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request,
|
|||
//"journeys": transitjourneys,
|
||||
"carpools": carpools,
|
||||
"vehicles": vehicles,
|
||||
"drivers": drivers,
|
||||
"solidarity_results": solidarity_results,
|
||||
}
|
||||
renderer.Render("journeys", w, r, files, state)
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
|||
}
|
||||
if modules["solidarity_service"] != nil && modules["solidarity_service"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Mobilité solidaire",
|
||||
Title: "Transport solidaire",
|
||||
Link: "/app/solidarity_service/",
|
||||
Active: menuState == solidarityserviceMenu,
|
||||
Icon: "hero:outline/map",
|
||||
|
|
|
@ -32,6 +32,8 @@ type BeneficiariesSolidarityListState struct {
|
|||
type SolidarityBookingsState struct {
|
||||
Bookings *solidarity_service.CreateBookingSolidarityResponse `json:"bookings"`
|
||||
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -71,31 +73,34 @@ func (s SolidarityBookingsState) JSONWithLimits(a int, b int) template.JS {
|
|||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||
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)
|
||||
state.ViewState = BeneficiariesSolidarityListState{
|
||||
Count: len(parcourmobAccounts),
|
||||
CacheId: cacheid,
|
||||
Beneficiaries: parcourmobAccounts,
|
||||
BeneficiariesSolidarity: accounts,
|
||||
|
||||
}
|
||||
|
||||
renderer.Render("solidarity_service", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse, parcourmobAccounts []mobilityaccountsstorage.Account) {
|
||||
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")
|
||||
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, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||
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")
|
||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||
state.ViewState = SolidarityListState {
|
||||
|
@ -103,7 +108,7 @@ func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseW
|
|||
CacheId: cacheid,
|
||||
Drivers: drivers,
|
||||
Beneficiaries: parcourmobAccounts,
|
||||
|
||||
BeneficiariesSolidarity: accounts,
|
||||
}
|
||||
|
||||
renderer.Render("solidarity_service", w, r, files, state)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package internal
|
||||
|
||||
|
||||
type SolidarityTransport struct {
|
||||
Drivers []any
|
||||
Beneficiaries []any
|
||||
}
|
Loading…
Reference in New Issue