create booking done
This commit is contained in:
parent
de060b2ecf
commit
5a89c8b24a
|
@ -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) {
|
||||
|
|
|
@ -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,22 +37,18 @@ 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"
|
||||
if PickupDate != "" {
|
||||
fmt.Println("no date selected")
|
||||
return
|
||||
}
|
||||
|
||||
dateParsed, err := time.Parse(layout, PickupDate)
|
||||
|
||||
if err != nil {
|
||||
|
@ -91,11 +101,10 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
|||
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],
|
||||
|
@ -110,15 +119,22 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
|||
},
|
||||
}
|
||||
|
||||
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &bookingData, accounts, cacheid)
|
||||
fmt.Println(BookingData.bookingData, "booking")
|
||||
|
||||
} else {
|
||||
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData, accounts, parcourmobAccounts, cacheid)
|
||||
|
||||
h.Renderer.SolidarityService(w, r, accounts, cacheid)
|
||||
}
|
||||
if r.Method == "POST" {
|
||||
} else if r.Method == "POST" {
|
||||
|
||||
booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &bookingData)
|
||||
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)
|
||||
|
@ -126,8 +142,11 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
|||
return
|
||||
}
|
||||
|
||||
h.Renderer.SolidarityServiceBooking(w, r, booking )
|
||||
h.Renderer.SolidarityServiceBooking(w, r, booking, parcourmobAccounts)
|
||||
|
||||
}else {
|
||||
|
||||
h.Renderer.SolidarityService(w, r, accounts, parcourmobAccounts, cacheid)
|
||||
}
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue