Compare commits

...

2 Commits

Author SHA1 Message Date
Maxime 5a89c8b24a create booking done 2024-09-25 15:16:02 +02:00
Maxime de060b2ecf front module mobilité solidaire 2024-09-19 11:14:02 +02:00
4 changed files with 122 additions and 42 deletions

View File

@ -28,6 +28,8 @@ import (
"git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
"github.com/google/uuid"
"github.com/gorilla/mux"
"google.golang.org/protobuf/types/known/structpb"
@ -324,11 +326,26 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
for _, o := range groupsresp.Groups {
organizations = append(organizations, o.ToStorageType())
}
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)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
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)
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) {

View File

@ -9,12 +9,26 @@ 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"
)
var BookingData Booking
type Booking struct {
bookingData solidarity_service.CreateBookingSolidarityRequest
}
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
accounts, err := h.beneficiaries(r)
parcourmobAccounts, err := h.beneficiaries(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{})
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
@ -23,19 +37,26 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
h.cache.PutWithTTL(cacheid, parcourmobAccounts, 1*time.Hour)
bookingData := solidarity_service.CreateBookingSolidarityRequest {
}
if r.Method == "GET" {
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"
dateParsed, err := time.Parse(layout, PickupDate)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var (
departuregeo *geojson.Feature
destinationgeo *geojson.Feature
@ -63,7 +84,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
}
}
request := &solidarity_service.DriverJourneysRequest{
request := solidarity_service.DriverJourneysRequest{
DepartureDate: timestamp,
Departure: &solidarity_service.Feature{
Lat: departuregeo.Geometry.Point[0],
@ -72,14 +93,18 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
},
}
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), request)
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), &request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
bookingData = solidarity_service.CreateBookingSolidarityRequest {
BookingData.bookingData = solidarity_service.CreateBookingSolidarityRequest {
Booking : &solidarity_service.BookingSolidarityRequest {
PassengerId: r.FormValue("passenger_id"),
DriverId: r.FormValue("driver_id"),
PassengerId: PassengerId,
DepartureAddress: &solidarity_service.Feature{
Lat: departuregeo.Geometry.Point[0],
Long: departuregeo.Geometry.Point[1],
@ -94,30 +119,34 @@ 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)
} else if r.Method == "POST" {
driverId := r.FormValue("driver_id")
id := uuid.New().String()
BookingData.bookingData.Booking.DriverId = driverId
BookingData.bookingData.Booking.Id = id
fmt.Println(BookingData.bookingData, "booking")
booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &BookingData.bookingData)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &bookingData, accounts, cacheid)
} else {
h.Renderer.SolidarityServiceBooking(w, r, booking, parcourmobAccounts)
h.Renderer.SolidarityService(w, r, accounts, cacheid)
}else {
h.Renderer.SolidarityService(w, r, accounts, parcourmobAccounts, cacheid)
}
// if r.Method == "POST" {
// booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &bookingData)
// if err != nil {
// fmt.Println(err)
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// h.Renderer.SolidarityServiceBooking(w, r, booking )
// }
}

View File

@ -7,6 +7,7 @@ import (
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
const beneficiariesMenu = "beneficiaries"
@ -53,7 +54,7 @@ type BeneficiariesDisplayState struct {
Beneficiary any
}
func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []fleetsstorage.Booking, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any, event interface{}) {
func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []fleetsstorage.Booking, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any, event interface{}, solidarity_bookings_list interface{}) {
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
state.ViewState = map[string]any{
@ -63,7 +64,8 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ
"file_types_map": file_types_map,
"documents": documents,
"organizations": organizations,
"event": event,
"event": event,
"solidarity_bookings": solidarity_bookings_list,
}
renderer.Render("beneficiaries_display", w, r, files, state)
}

View File

@ -5,8 +5,8 @@ import (
"html/template"
"net/http"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
const solidarityserviceMenu = "solidarity_service"
@ -15,53 +15,85 @@ const solidarityserviceMenu = "solidarity_service"
type SolidarityListState struct {
Count int `json:"count"`
CacheId string `json:"cache_id"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
type BeneficiariesSolidarityListState struct {
Count int `json:"count"`
CacheId string `json:"cache_id"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
type SolidarityBookingsState struct {
Bookings *solidarity_service.CreateBookingSolidarityResponse `json:"bookings"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
func (s BeneficiariesSolidarityListState) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s BeneficiariesSolidarityListState) JSONWithLimits(a int, b int) template.JS {
if b < 5 {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
func (s SolidarityListState) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS {
if b < len(s.Beneficiaries) {
if b < 5 {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts []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 = BeneficiariesListState{
Count: len(accounts),
state.ViewState = BeneficiariesSolidarityListState{
Count: len(parcourmobAccounts),
CacheId: cacheid,
Beneficiaries: accounts,
BeneficiariesSolidarity: accounts,
Beneficiaries: parcourmobAccounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, booking *solidarity_service.CreateBookingSolidarityResponse) {
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse, parcourmobAccounts []mobilityaccountsstorage.Account) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = map[string]any{
"booking": booking,
state.ViewState = SolidarityBookingsState{
Bookings: bookings,
Beneficiaries: parcourmobAccounts,
}
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 []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 {
Count: len(accounts),
Beneficiaries: accounts,
Count: len(parcourmobAccounts),
BeneficiariesSolidarity: accounts,
CacheId: cacheid,
Drivers: drivers,
Beneficiaries: parcourmobAccounts,
}
renderer.Render("solidarity_service", w, r, files, state)