parcoursmob/renderer/solidarity_service.go

101 lines
3.7 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-08-28 12:10:03 +00:00
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
2024-09-25 13:16:02 +00:00
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
2024-05-02 07:54:51 +00:00
)
const solidarityserviceMenu = "solidarity_service"
type SolidarityListState struct {
Count int `json:"count"`
2024-09-17 08:30:29 +00:00
CacheId string `json:"cache_id"`
2024-09-25 13:16:02 +00:00
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
2024-09-25 13:16:02 +00:00
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
2024-09-25 13:16:02 +00:00
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 {
2024-09-25 13:16:02 +00:00
if b < 5 {
s.Beneficiaries = s.Beneficiaries[a:b]
}
return s.JSON()
}
2024-09-25 13:16:02 +00:00
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)
2024-09-25 13:16:02 +00:00
state.ViewState = BeneficiariesSolidarityListState{
Count: len(parcourmobAccounts),
CacheId: cacheid,
2024-09-25 13:16:02 +00:00
BeneficiariesSolidarity: accounts,
Beneficiaries: parcourmobAccounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}
2024-09-25 13:16:02 +00:00
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse, parcourmobAccounts []mobilityaccountsstorage.Account) {
2024-08-28 12:10:03 +00:00
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.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,
Beneficiaries: parcourmobAccounts,
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-09-25 13:16:02 +00:00
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) {
2024-08-28 12:10:03 +00:00
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = SolidarityListState {
2024-09-25 13:16:02 +00:00
Count: len(parcourmobAccounts),
BeneficiariesSolidarity: accounts,
CacheId: cacheid,
Drivers: drivers,
2024-09-25 13:16:02 +00:00
Beneficiaries: parcourmobAccounts,
}
renderer.Render("solidarity_service", w, r, files, state)
}