parcoursmob/renderer/solidarity_service.go

128 lines
4.8 KiB
Go
Raw Normal View History

2024-05-02 07:54:51 +00:00
package renderer
import (
"encoding/json"
"html/template"
2024-05-02 07:54:51 +00:00
"net/http"
2024-09-25 13:16:02 +00:00
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
2024-11-29 10:43:47 +00:00
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
2024-05-02 07:54:51 +00:00
)
const solidarityserviceMenu = "solidarity_service"
type SolidarityListState struct {
2024-12-18 14:05:58 +00:00
Count int `json:"count"`
CacheId string `json:"cache_id"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
Bookings *solidarity_service.GetAllBookingsSolidarityResponse `json:"bookings"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
2024-09-25 13:16:02 +00:00
type BeneficiariesSolidarityListState struct {
2024-11-29 10:43:47 +00:00
Count int `json:"count"`
CacheId string `json:"cache_id"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Drivers *solidarity_service.GetAllDriversResponse `json:"drivers"`
2024-12-16 09:12:40 +00:00
Bookings *solidarity_service.GetAllBookingsSolidarityResponse `json:"bookings"`
2024-12-18 14:05:58 +00:00
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
2024-09-25 13:16:02 +00:00
}
type SolidarityBookingsState struct {
Bookings *solidarity_service.CreateBookingSolidarityResponse `json:"bookings"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
2024-11-22 16:26:32 +00:00
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
2024-09-25 13:16:02 +00:00
}
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 {
2024-09-25 13:16:02 +00:00
if b < 5 {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
func (s SolidarityBookingsState) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
}
func (s SolidarityBookingsState) JSONWithLimits(a int, b int) template.JS {
if b < 5 {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
2024-12-16 09:12:40 +00:00
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts *solidarity_service.GetAllPassengersResponse, drivers *solidarity_service.GetAllDriversResponse, parcourmobAccounts []mobilityaccountsstorage.Account, bookings *solidarity_service.GetAllBookingsSolidarityResponse, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
2024-09-25 13:16:02 +00:00
state.ViewState = BeneficiariesSolidarityListState{
Count: len(parcourmobAccounts),
CacheId: cacheid,
2024-09-25 13:16:02 +00:00
Beneficiaries: parcourmobAccounts,
2024-11-22 16:26:32 +00:00
BeneficiariesSolidarity: accounts,
2024-11-29 10:43:47 +00:00
Drivers: drivers,
2024-12-16 09:12:40 +00:00
Bookings: bookings,
2024-11-22 16:26:32 +00:00
}
renderer.Render("solidarity_service", w, r, files, state)
}
2024-12-18 14:05:58 +00:00
func (renderer *Renderer) CreateBookingHome(w http.ResponseWriter, r *http.Request ) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
renderer.Render("solidarity_service", w, r, files, state)
}
2024-11-28 10:57:36 +00:00
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
2024-05-02 07:54:51 +00:00
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
2024-09-25 13:16:02 +00:00
state.ViewState = SolidarityBookingsState{
Bookings: bookings,
2024-08-28 12:10:03 +00:00
}
2024-05-02 07:54:51 +00:00
renderer.Render("solidarity_service", w, r, files, state)
}
2024-11-28 10:57:36 +00:00
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
2024-12-18 14:05:58 +00:00
state.ViewState = SolidarityListState{
Drivers: drivers,
}
renderer.Render("solidarity_service", w, r, files, state)
}
2024-12-04 16:46:25 +00:00
func (renderer *Renderer) CreateDriver(w http.ResponseWriter, r *http.Request) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create_driver.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
renderer.Render("solidarity_service", w, r, files, state)
}