Compare commits
No commits in common. "5a89c8b24a1ceedc2ed0bd9e72678229d518d2a0" and "13a34ad124f2d562c03d740ded9a9119dec9c198" have entirely different histories.
5a89c8b24a
...
13a34ad124
|
@ -28,8 +28,6 @@ import (
|
||||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
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/google/uuid"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"google.golang.org/protobuf/types/known/structpb"
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
|
@ -326,26 +324,11 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
||||||
for _, o := range groupsresp.Groups {
|
for _, o := range groupsresp.Groups {
|
||||||
organizations = append(organizations, o.ToStorageType())
|
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")
|
beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types")
|
||||||
file_types_map := h.config.GetStringMapString("storage.files.file_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, solidarity_bookings_list)
|
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -9,26 +9,12 @@ import (
|
||||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
geojson "github.com/paulmach/go.geojson"
|
geojson "github.com/paulmach/go.geojson"
|
||||||
"google.golang.org/protobuf/types/known/emptypb"
|
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"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) {
|
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
parcourmobAccounts, err := h.beneficiaries(r)
|
accounts, 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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
@ -37,26 +23,19 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||||
|
|
||||||
cacheid := uuid.NewString()
|
cacheid := uuid.NewString()
|
||||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||||
h.cache.PutWithTTL(cacheid, parcourmobAccounts, 1*time.Hour)
|
|
||||||
|
|
||||||
|
bookingData := solidarity_service.CreateBookingSolidarityRequest {
|
||||||
|
}
|
||||||
|
|
||||||
if r.Method == "GET" && r.FormValue("date") != ""{
|
if r.Method == "GET" {
|
||||||
|
|
||||||
DepartureAddress := r.FormValue("departure");
|
DepartureAddress := r.FormValue("departure");
|
||||||
DestinationAddress := r.FormValue("destination");
|
DestinationAddress := r.FormValue("destination");
|
||||||
PickupDate := r.FormValue("date");
|
PickupDate := r.FormValue("date");
|
||||||
PassengerId := r.FormValue("passenger_id")
|
|
||||||
|
|
||||||
layout := "2006-01-02T15:04"
|
layout := "2006-01-02T15:04"
|
||||||
|
|
||||||
dateParsed, err := time.Parse(layout, PickupDate)
|
dateParsed, err := time.Parse(layout, PickupDate)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
departuregeo *geojson.Feature
|
departuregeo *geojson.Feature
|
||||||
destinationgeo *geojson.Feature
|
destinationgeo *geojson.Feature
|
||||||
|
@ -84,7 +63,7 @@ func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Reque
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request := solidarity_service.DriverJourneysRequest{
|
request := &solidarity_service.DriverJourneysRequest{
|
||||||
DepartureDate: timestamp,
|
DepartureDate: timestamp,
|
||||||
Departure: &solidarity_service.Feature{
|
Departure: &solidarity_service.Feature{
|
||||||
Lat: departuregeo.Geometry.Point[0],
|
Lat: departuregeo.Geometry.Point[0],
|
||||||
|
@ -93,18 +72,14 @@ 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.bookingData = solidarity_service.CreateBookingSolidarityRequest {
|
bookingData = solidarity_service.CreateBookingSolidarityRequest {
|
||||||
Booking : &solidarity_service.BookingSolidarityRequest {
|
Booking : &solidarity_service.BookingSolidarityRequest {
|
||||||
|
|
||||||
PassengerId: PassengerId,
|
PassengerId: r.FormValue("passenger_id"),
|
||||||
|
DriverId: r.FormValue("driver_id"),
|
||||||
DepartureAddress: &solidarity_service.Feature{
|
DepartureAddress: &solidarity_service.Feature{
|
||||||
Lat: departuregeo.Geometry.Point[0],
|
Lat: departuregeo.Geometry.Point[0],
|
||||||
Long: departuregeo.Geometry.Point[1],
|
Long: departuregeo.Geometry.Point[1],
|
||||||
|
@ -119,34 +94,30 @@ 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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &bookingData, accounts, cacheid)
|
||||||
|
|
||||||
h.Renderer.SolidarityServiceBooking(w, r, booking, parcourmobAccounts)
|
} else {
|
||||||
|
|
||||||
}else {
|
h.Renderer.SolidarityService(w, r, accounts, cacheid)
|
||||||
|
|
||||||
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 )
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const beneficiariesMenu = "beneficiaries"
|
const beneficiariesMenu = "beneficiaries"
|
||||||
|
@ -54,7 +53,7 @@ type BeneficiariesDisplayState struct {
|
||||||
Beneficiary any
|
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{}, solidarity_bookings_list 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{}) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
||||||
state.ViewState = map[string]any{
|
state.ViewState = map[string]any{
|
||||||
|
@ -64,8 +63,7 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ
|
||||||
"file_types_map": file_types_map,
|
"file_types_map": file_types_map,
|
||||||
"documents": documents,
|
"documents": documents,
|
||||||
"organizations": organizations,
|
"organizations": organizations,
|
||||||
"event": event,
|
"event": event,
|
||||||
"solidarity_bookings": solidarity_bookings_list,
|
|
||||||
}
|
}
|
||||||
renderer.Render("beneficiaries_display", w, r, files, state)
|
renderer.Render("beneficiaries_display", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
|
||||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||||
|
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
const solidarityserviceMenu = "solidarity_service"
|
const solidarityserviceMenu = "solidarity_service"
|
||||||
|
@ -15,85 +15,53 @@ const solidarityserviceMenu = "solidarity_service"
|
||||||
type SolidarityListState struct {
|
type SolidarityListState struct {
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
CacheId string `json:"cache_id"`
|
CacheId string `json:"cache_id"`
|
||||||
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||||
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
|
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 {
|
func (s SolidarityListState) JSON() template.JS {
|
||||||
result, _ := json.Marshal(s)
|
result, _ := json.Marshal(s)
|
||||||
return template.JS(result)
|
return template.JS(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS {
|
func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS {
|
||||||
if b < 5 {
|
if b < len(s.Beneficiaries) {
|
||||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||||
}
|
}
|
||||||
return s.JSON()
|
return s.JSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||||
state.ViewState = BeneficiariesSolidarityListState{
|
state.ViewState = BeneficiariesListState{
|
||||||
Count: len(parcourmobAccounts),
|
Count: len(accounts),
|
||||||
CacheId: cacheid,
|
CacheId: cacheid,
|
||||||
BeneficiariesSolidarity: accounts,
|
Beneficiaries: accounts,
|
||||||
Beneficiaries: parcourmobAccounts,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("solidarity_service", w, r, files, state)
|
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, booking *solidarity_service.CreateBookingSolidarityResponse) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||||
state.ViewState = SolidarityBookingsState{
|
state.ViewState = map[string]any{
|
||||||
Bookings: bookings,
|
"booking": booking,
|
||||||
Beneficiaries: parcourmobAccounts,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("solidarity_service", w, r, files, state)
|
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 *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest, accounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||||
state.ViewState = SolidarityListState {
|
state.ViewState = SolidarityListState {
|
||||||
Count: len(parcourmobAccounts),
|
Count: len(accounts),
|
||||||
BeneficiariesSolidarity: accounts,
|
Beneficiaries: accounts,
|
||||||
CacheId: cacheid,
|
CacheId: cacheid,
|
||||||
Drivers: drivers,
|
Drivers: drivers,
|
||||||
Beneficiaries: parcourmobAccounts,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.Render("solidarity_service", w, r, files, state)
|
renderer.Render("solidarity_service", w, r, files, state)
|
||||||
|
|
Loading…
Reference in New Issue