Compare commits
71 Commits
modifyAnEv
...
test
| Author | SHA1 | Date | |
|---|---|---|---|
| 81e81f8763 | |||
| 5f64b6c71a | |||
| 51dcaf01c8 | |||
| bd91ce1572 | |||
| edb03ae3b4 | |||
| 5ea89bf0b2 | |||
| 18e890ceed | |||
| b717be9b99 | |||
| ddb08cf671 | |||
| 4fe479c1fb | |||
| b0dd81bf67 | |||
|
|
3bfd2e1bfe | ||
|
|
b5154bf9be | ||
|
|
96823f3289 | ||
|
|
93cab33fb9 | ||
|
|
d5bc764ef3 | ||
|
|
1aeb6d50ef | ||
| f26d792b8b | |||
| bfd14d7f4c | |||
| 31e5eadc73 | |||
| 8f20a12bc5 | |||
| 8e2b0ada32 | |||
| bcddbc0d58 | |||
| ce8e30f999 | |||
| 78877f139f | |||
| 5476ea1c99 | |||
| 59c6ce9da6 | |||
|
|
850633eac7 | ||
|
|
7847b4c31f | ||
|
|
a63a4ad1c2 | ||
|
|
232764e7d7 | ||
|
|
e4418f26e0 | ||
|
|
a05942b7ed | ||
|
|
1b2902c632 | ||
|
|
c9b326c49a | ||
|
|
c3e67cb9dd | ||
|
|
795066b6e5 | ||
|
|
bdcb386dff | ||
|
|
64521c01c1 | ||
|
|
3b9ac66965 | ||
| f09d9d0a16 | |||
|
|
11e2375456 | ||
|
|
e11514b6d5 | ||
|
|
3bfce72512 | ||
|
|
335656ec75 | ||
|
|
167e8cfe2e | ||
| f698891865 | |||
|
|
f023a7bbff | ||
|
|
d1818b6251 | ||
|
|
fa065f2a43 | ||
|
|
e559359ff0 | ||
|
|
9965271788 | ||
|
|
97ebcf480e | ||
| 193f5dfb6f | |||
| 49de2f22c4 | |||
| ab8cbf6f73 | |||
| 10bde53c5e | |||
| 28c8fa8a90 | |||
| 11851fec61 | |||
| 696cd1d87f | |||
|
|
372647b3b9 | ||
|
|
56c1b45f45 | ||
|
|
62f64747c3 | ||
| 56d0914568 | |||
| 439f819989 | |||
|
|
40cf6012a6 | ||
|
|
774a3c2301 | ||
|
|
e03f31d3f4 | ||
|
|
a2b644d548 | ||
|
|
4c42d3efd3 | ||
|
|
12a8a359ab |
@@ -19,7 +19,7 @@ COPY . .
|
||||
|
||||
RUN go mod download && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server
|
||||
|
||||
RUN rm -r themes/*
|
||||
# RUN rm -r themes/*
|
||||
RUN git clone --depth 1 https://git.coopgo.io/coopgo-apps/parcoursmob-default-theme themes/default
|
||||
RUN git clone -b spie06 --depth 1 https://git.coopgo.io/coopgo-apps/parcoursmob-default-theme themes/spie06
|
||||
|
||||
|
||||
@@ -10,3 +10,5 @@ This new version of PARCOURSMOB brings :
|
||||
- A configurable and themeable approach of rendering web pages : the default theme is located in the folder [themes/default/](themes/default/)
|
||||
- A modular architecture based on groups and access rights, using [COOPGO Groups Management](https://git.coopgo.io/coopgo-groups-management)
|
||||
- A distributed cache system through [etcd](https://etcd.io/) to handle distributed state management like pagination in a cloud native way
|
||||
|
||||
|
||||
|
||||
44
go.mod
44
go.mod
@@ -8,7 +8,7 @@ go 1.18
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
||||
|
||||
replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
||||
// replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
|
||||
|
||||
@@ -23,25 +23,30 @@ require (
|
||||
github.com/spf13/viper v1.13.0
|
||||
gitlab.scity.coop/maas/navitia-golang v0.0.0-20220429110621-5c22d6efdd0c
|
||||
go.etcd.io/etcd/client/v3 v3.5.4
|
||||
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539
|
||||
golang.org/x/image v0.5.0
|
||||
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
|
||||
google.golang.org/grpc v1.48.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
||||
require (
|
||||
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9
|
||||
git.coopgo.io/coopgo-platform/agenda v0.0.0-20230222135722-e55cf41e203b
|
||||
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15
|
||||
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b
|
||||
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0
|
||||
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe
|
||||
git.coopgo.io/coopgo-platform/fleets v0.0.0-20230519092636-41bf03682ca9
|
||||
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230117140716-312200e21063
|
||||
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20221107003506-e2ff98094b81
|
||||
github.com/gorilla/securecookie v1.1.1
|
||||
github.com/minio/minio-go/v7 v7.0.43
|
||||
github.com/ory/viper v1.7.5
|
||||
github.com/xuri/excelize/v2 v2.7.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
|
||||
github.com/cespare/xxhash v1.1.0 // indirect
|
||||
github.com/coreos/go-semver v0.3.0 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
|
||||
github.com/dgraph-io/ristretto v0.0.3 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
@@ -50,35 +55,51 @@ require (
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/gorilla/csrf v1.7.1 // indirect
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.15.9 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/goveralls v0.0.6 // indirect
|
||||
github.com/mb0/wkt v0.0.0-20170420051526-a30afd545ee1 // indirect
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/sha256-simd v1.0.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||
github.com/ory/fosite v0.42.2 // indirect
|
||||
github.com/ory/go-acc v0.2.6 // indirect
|
||||
github.com/ory/go-convenience v0.1.0 // indirect
|
||||
github.com/ory/x v0.0.214 // indirect
|
||||
github.com/pborman/uuid v1.2.0 // indirect
|
||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pquerna/cachecontrol v0.1.0 // indirect
|
||||
github.com/richardlehane/mscfb v1.0.4 // indirect
|
||||
github.com/richardlehane/msoleps v1.0.3 // indirect
|
||||
github.com/rs/xid v1.4.0 // indirect
|
||||
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/spf13/afero v1.8.2 // indirect
|
||||
github.com/spf13/cast v1.5.0 // indirect
|
||||
github.com/spf13/cobra v1.0.0 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.4.1 // indirect
|
||||
github.com/tidwall/pretty v1.1.0 // indirect
|
||||
github.com/twpayne/go-geom v1.3.6 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.1 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
|
||||
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
|
||||
@@ -86,11 +107,12 @@ require (
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.17.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
|
||||
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/crypto v0.8.0 // indirect
|
||||
golang.org/x/net v0.9.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.7.0 // indirect
|
||||
golang.org/x/text v0.9.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
|
||||
@@ -10,10 +10,14 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
"git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
@@ -64,8 +68,39 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
sort.Sort(sorting.GroupsByName(groups))
|
||||
////////////////////////////////////add event////////////////////////////////////////////
|
||||
rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
})
|
||||
|
||||
h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
responses := []agendastorage.Event{}
|
||||
|
||||
groupids := []string{}
|
||||
for _, e := range rresp.Events {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
responses = append(responses, e.ToStorageType())
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(responses))
|
||||
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groupps := map[string]any{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groupps[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings, responses)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -333,29 +368,146 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
|
||||
return
|
||||
}
|
||||
|
||||
func filteVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
for _, n := range v.Administrators {
|
||||
if n == group.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
request := &fleets.GetBookingsRequest{}
|
||||
resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request)
|
||||
bookings := []fleetsstorage.Booking{}
|
||||
administrators := []string{}
|
||||
reequest := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
}
|
||||
reesp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), reequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
vehicles := []fleetsstorage.Vehicle{}
|
||||
for _, vehiicle := range reesp.Vehicles {
|
||||
|
||||
v := vehiicle.ToStorageType()
|
||||
adminfound := false
|
||||
for _, a := range administrators {
|
||||
if a == v.Administrators[0] {
|
||||
adminfound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !adminfound {
|
||||
administrators = append(administrators, v.Administrators[0])
|
||||
}
|
||||
|
||||
vehicleBookings := []fleetsstorage.Booking{}
|
||||
for _, b := range v.Bookings {
|
||||
if b.Unavailableto.After(time.Now()) {
|
||||
vehicleBookings = append(vehicleBookings, b)
|
||||
}
|
||||
}
|
||||
|
||||
v.Bookings = vehicleBookings
|
||||
|
||||
vehicles = append(vehicles, v)
|
||||
|
||||
}
|
||||
groups := map[string]any{}
|
||||
|
||||
if len(administrators) > 0 {
|
||||
admingroups, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: administrators,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, g := range admingroups.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
|
||||
}
|
||||
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||
h.Renderer.AdminStatVehicles(w, r, vehicles, bookings, groups)
|
||||
}
|
||||
|
||||
func (h ApplicationHandler) AdminStatBookings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
vehicles := map[string]fleetsstorage.Vehicle{}
|
||||
bookings := []fleetsstorage.Booking{}
|
||||
|
||||
reequest := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
}
|
||||
reesp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), reequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
bookings := []storage.Booking{}
|
||||
beneficiaries_ids := []string{}
|
||||
|
||||
for _, b := range resp.Bookings {
|
||||
booking := b.ToStorageType()
|
||||
bookings = append(bookings, booking)
|
||||
for _, vehicle := range reesp.Vehicles {
|
||||
|
||||
v := vehicle.ToStorageType()
|
||||
|
||||
for _, b := range v.Bookings {
|
||||
bookings = append(bookings, b)
|
||||
beneficiaries_ids = append(beneficiaries_ids, b.Driver)
|
||||
}
|
||||
|
||||
vehicles[v.ID] = v
|
||||
|
||||
}
|
||||
|
||||
groups := map[string]any{}
|
||||
|
||||
admingroups, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), &groupsmanagement.GetGroupsRequest{
|
||||
Namespaces: []string{"parcoursmob_organizations"},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, g := range admingroups.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||
Accountids: beneficiaries_ids,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_map := map[string]any{}
|
||||
for _, ben := range beneficiaries.Accounts {
|
||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||
}
|
||||
|
||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||
|
||||
vehicles, _ := h.services.GetVehiclesMap()
|
||||
groups, _ := h.services.GetGroupsMap()
|
||||
|
||||
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
|
||||
h.Renderer.AdminStatBookings(w, r, vehicles, bookings, groups, beneficiaries_map)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
|
||||
@@ -395,3 +547,49 @@ func (h *ApplicationHandler) groupmembers(groupid string) (groupmembers []mobili
|
||||
|
||||
return groupmembers, admins, err
|
||||
}
|
||||
|
||||
func (h ApplicationHandler) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request) {
|
||||
beneficiaries, err := h.services.GetBeneficiaries()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, beneficiaries, 1*time.Hour)
|
||||
h.Renderer.AdminStatBeneficaires(w, r, beneficiaries, cacheid)
|
||||
}
|
||||
|
||||
func (h ApplicationHandler) AdminStatEvents(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
responses := []agendastorage.Event{}
|
||||
|
||||
groupids := []string{}
|
||||
for _, e := range resp.Events {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
responses = append(responses, e.ToStorageType())
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(responses))
|
||||
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]any{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
h.Renderer.AdminStatEvents(w, r, responses, groups)
|
||||
}
|
||||
|
||||
@@ -68,10 +68,44 @@ func (h *ApplicationHandler) AgendaHome(w http.ResponseWriter, r *http.Request)
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
h.Renderer.AgendaHome(w, r, responses, groups)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) AgendaHistory(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
//Maxdate: timestamppb.New(time.Now().Add(24 * time.Hour)),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
responses := []agendastorage.Event{}
|
||||
|
||||
groupids := []string{}
|
||||
for _, e := range resp.Events {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
responses = append(responses, e.ToStorageType())
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(responses))
|
||||
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]any{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
h.Renderer.AgendaHistory(w, r, responses, groups)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) AgendaCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
// Get current group
|
||||
@@ -227,13 +261,13 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
dis := fmt.Sprint(current_user_claims["first_name"]) + " " + fmt.Sprint(current_user_claims["last_name"])
|
||||
subscriber := r.FormValue("subscriber")
|
||||
data := map[string]any{
|
||||
"subscribed_by": map[string]any{
|
||||
"user": map[string]any{
|
||||
"id": current_user_token.Subject,
|
||||
"display_name": dis,
|
||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||
"email": current_user_claims["email"].(string),
|
||||
},
|
||||
"group": map[string]any{
|
||||
"id": current_group.ID,
|
||||
@@ -450,11 +484,204 @@ func (h *ApplicationHandler) AgendaDeleteEvent(w http.ResponseWriter, r *http.Re
|
||||
h.Renderer.AgendaDeleteEvent(w, r, resp.Event.ToStorageType())
|
||||
}
|
||||
|
||||
// func contains[V string](s []V, e V) bool {
|
||||
// for _, a := range s {
|
||||
// if a == e {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
///////////////////////////Delete subscriber///////////////////////////////
|
||||
func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
eventId := vars["eventid"]
|
||||
subscribeid := vars["subscribeid"]
|
||||
s_b_id := ""
|
||||
s_b_name := ""
|
||||
s_b_email := ""
|
||||
s_b_group_id := ""
|
||||
s_b_group_name := ""
|
||||
request := &agenda.GetEventRequest{
|
||||
Id: eventId,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for i := range resp.Event.Subscriptions {
|
||||
if resp.Event.Subscriptions[i].Subscriber == subscribeid {
|
||||
subscribed_by_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
|
||||
subscribed_by_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
|
||||
subscribed_by_email := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
|
||||
subscribed_by_group_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
|
||||
subscribed_by_group_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
|
||||
s_b_id = subscribed_by_id
|
||||
s_b_name = subscribed_by_name
|
||||
s_b_email = subscribed_by_email
|
||||
s_b_group_id = subscribed_by_group_id
|
||||
s_b_group_name = subscribed_by_group_name
|
||||
}
|
||||
}
|
||||
|
||||
current_group, err := h.currentGroup(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
current_user_token, current_user_claims, err := h.currentUser(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]any{
|
||||
"subscribed_by": map[string]any{
|
||||
"user": map[string]any{
|
||||
"id": s_b_id,
|
||||
"display_name": s_b_name,
|
||||
"email": s_b_email,
|
||||
},
|
||||
"group": map[string]any{
|
||||
"id": s_b_group_id,
|
||||
"name": s_b_group_name,
|
||||
},
|
||||
},
|
||||
"unsubscribed_by": map[string]any{
|
||||
"user": map[string]any{
|
||||
"id": current_user_token.Subject,
|
||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||
"email": current_user_claims["email"],
|
||||
},
|
||||
"group": map[string]any{
|
||||
"id": current_group.ID,
|
||||
"name": current_group.Data["name"],
|
||||
},
|
||||
},
|
||||
"motif": r.FormValue("motif"),
|
||||
}
|
||||
|
||||
datapb, err := structpb.NewStruct(data)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method == "POST" {
|
||||
request := &agenda.DeleteSubscriptionRequest{
|
||||
Subscriber: subscribeid,
|
||||
Eventid: eventId,
|
||||
Data: datapb,
|
||||
}
|
||||
|
||||
data := map[string]any{
|
||||
"motif": r.FormValue("motif"),
|
||||
"user": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||
"subscriber": fmt.Sprintf("http://localhost:9000/app/beneficiaries/%s", subscribeid),
|
||||
"link": fmt.Sprintf("http://localhost:9000/app/agenda/%s", eventId),
|
||||
}
|
||||
|
||||
// récupérer l'adresse mail de l'utilisateur qui a créé l'événement
|
||||
mail := s_b_email
|
||||
fmt.Println(mail)
|
||||
|
||||
_, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("delete_subscriber.request", mail, data); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", eventId), http.StatusFound)
|
||||
return
|
||||
}
|
||||
h.Renderer.AgendaDeleteSubscribeEvent(w, r, eventId)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// /////////////////////History Event////////////////////////
|
||||
func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
eventId := vars["eventid"]
|
||||
request := &agenda.GetEventRequest{
|
||||
Id: eventId,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
grouprequest := &groupsmanagement.GetGroupRequest{
|
||||
Id: resp.Event.Owners[0],
|
||||
}
|
||||
|
||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), grouprequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
subscribers := map[string]any{}
|
||||
|
||||
accids := []string{}
|
||||
for _, v := range resp.Event.DeletedSubscription {
|
||||
accids = append(accids, v.Subscriber)
|
||||
}
|
||||
|
||||
subscriberresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
||||
context.TODO(),
|
||||
&mobilityaccounts.GetAccountsBatchRequest{
|
||||
Accountids: accids,
|
||||
},
|
||||
)
|
||||
|
||||
if err == nil {
|
||||
for _, sub := range subscriberresp.Accounts {
|
||||
subscribers[sub.Id] = sub.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
accountids := []string{}
|
||||
for _, m := range group.Members {
|
||||
if !contains(resp.Event.DeletedSubscription, m) {
|
||||
accountids = append(accountids, m)
|
||||
}
|
||||
}
|
||||
|
||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
||||
context.TODO(),
|
||||
&mobilityaccounts.GetAccountsBatchRequest{
|
||||
Accountids: accountids,
|
||||
},
|
||||
)
|
||||
|
||||
accounts := []any{}
|
||||
|
||||
if err == nil {
|
||||
for _, acc := range accountresp.Accounts {
|
||||
accounts = append(accounts, acc)
|
||||
}
|
||||
}
|
||||
|
||||
h.Renderer.AgendaHistoryEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
|
||||
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||
|
||||
h.Renderer.BeneficiariesList(w, r, accounts, cacheid)
|
||||
}
|
||||
|
||||
@@ -269,7 +268,7 @@ func (h *ApplicationHandler) BeneficiaryDocuments(w http.ResponseWriter, r *http
|
||||
beneficiaryID := vars["beneficiaryid"]
|
||||
|
||||
//r.ParseForm()
|
||||
r.ParseMultipartForm(10 * 1024 * 1024)
|
||||
r.ParseMultipartForm(100 * 1024 * 1024)
|
||||
|
||||
document_type := r.FormValue("type")
|
||||
document_name := r.FormValue("name")
|
||||
|
||||
@@ -5,14 +5,26 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
geojson "github.com/paulmach/go.geojson"
|
||||
"gitlab.scity.coop/maas/navitia-golang"
|
||||
"gitlab.scity.coop/maas/navitia-golang/types"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
var Depart any
|
||||
var Arrive any
|
||||
|
||||
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
|
||||
@@ -144,3 +156,413 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
h.Renderer.JourneysSearch(w, r, carpoolresults, journeys, vehicles, searched, departuregeo, destinationgeo, departuredate, departuretime)
|
||||
}
|
||||
|
||||
type GroupsModule []groupstorage.Group
|
||||
|
||||
func (a GroupsModule) Len() int { return len(a) }
|
||||
func (a GroupsModule) Less(i, j int) bool {
|
||||
return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0
|
||||
}
|
||||
func (a GroupsModule) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
func (h *ApplicationHandler) GroupsGestion(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
request := &groupsmanagement.GetGroupsRequest{
|
||||
Namespaces: []string{"parcoursmob_groups_covoiturage"},
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var groups = []groupstorage.Group{}
|
||||
|
||||
for _, group := range resp.Groups {
|
||||
g := group.ToStorageType()
|
||||
groups = append(groups, g)
|
||||
}
|
||||
|
||||
cacheid := uuid.NewString()
|
||||
|
||||
sort.Sort(GroupsModule(groups))
|
||||
h.cache.PutWithTTL(cacheid, groups, 1*time.Hour)
|
||||
|
||||
h.Renderer.GroupsGestion(w, r, groups, cacheid)
|
||||
}
|
||||
func filterAcc(r *http.Request, a *mobilityaccounts.Account) bool {
|
||||
searchFilter, ok := r.URL.Query()["search"]
|
||||
|
||||
if ok && len(searchFilter[0]) > 0 {
|
||||
name := a.Data.AsMap()["first_name"].(string) + " " + a.Data.AsMap()["last_name"].(string)
|
||||
if !strings.Contains(strings.ToLower(name), strings.ToLower(searchFilter[0])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) CreateGroup(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var beneficiary any
|
||||
var (
|
||||
departurgeo *geojson.Feature
|
||||
dstinationgeo *geojson.Feature
|
||||
)
|
||||
searched := false
|
||||
|
||||
if r.FormValue("beneficiaryid") != "" {
|
||||
|
||||
searched = true
|
||||
|
||||
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
|
||||
Id: r.FormValue("beneficiaryid"),
|
||||
}
|
||||
|
||||
respbeneficiary, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), requestbeneficiary)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiary = respbeneficiary.Account.ToStorageType()
|
||||
|
||||
if r.Method == "POST" {
|
||||
departure := r.FormValue("departure")
|
||||
destination := r.FormValue("destination")
|
||||
|
||||
if departure != "" && destination != "" {
|
||||
|
||||
var err error
|
||||
|
||||
departurgeo, err = geojson.UnmarshalFeature([]byte(departure))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
dstinationgeo, err = geojson.UnmarshalFeature([]byte(destination))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
if r.FormValue("departure") != "" {
|
||||
var a any
|
||||
json.Unmarshal([]byte(r.FormValue("departure")), &a)
|
||||
|
||||
Depart = a
|
||||
}
|
||||
if r.FormValue("destination") != "" {
|
||||
var a any
|
||||
json.Unmarshal([]byte(r.FormValue("destination")), &a)
|
||||
|
||||
Arrive = a
|
||||
}
|
||||
r.ParseForm()
|
||||
|
||||
if r.FormValue("name") == "" {
|
||||
|
||||
fmt.Println("invalid name")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if r.FormValue("number") == "" {
|
||||
|
||||
fmt.Println("invalid number of personne")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
planDays := map[string]any{
|
||||
"lundi": r.FormValue("lundi") == "on",
|
||||
"mardi": r.FormValue("mardi") == "on",
|
||||
"mercredi": r.FormValue("mercredi") == "on",
|
||||
"jeudi": r.FormValue("jeudi") == "on",
|
||||
"vendredi": r.FormValue("vendredi") == "on",
|
||||
"samedi": r.FormValue("samedi") == "on",
|
||||
"dimanche": r.FormValue("dimanche") == "on",
|
||||
}
|
||||
|
||||
groupidd := uuid.NewString()
|
||||
|
||||
dataMap := map[string]any{
|
||||
"name": r.FormValue("name"),
|
||||
"number": r.FormValue("number"),
|
||||
"driver_first_name": respbeneficiary.Account.ToStorageType().Data["first_name"],
|
||||
"driver_last_name": respbeneficiary.Account.ToStorageType().Data["last_name"],
|
||||
"depart": Depart,
|
||||
"arrive": Arrive,
|
||||
"departdate": r.FormValue("departdate"),
|
||||
"date": r.FormValue("date"),
|
||||
"enddate": r.FormValue("enddate"),
|
||||
"departtime": r.FormValue("departtime"),
|
||||
"time": r.FormValue("time"),
|
||||
|
||||
"planDays": planDays,
|
||||
"recurrent": r.FormValue("recurrent"),
|
||||
"pontuelle": r.FormValue("ponctuelle"),
|
||||
}
|
||||
|
||||
data, err := structpb.NewValue(dataMap)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
request_organization := &groupsmanagement.AddGroupRequest{
|
||||
Group: &groupsmanagement.Group{
|
||||
Id: groupidd,
|
||||
Namespace: "parcoursmob_groups_covoiturage",
|
||||
Data: data.GetStructValue(),
|
||||
},
|
||||
}
|
||||
|
||||
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", request_organization.Group.ToStorageType().ID), http.StatusFound)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
accountsBeneficaire, err := h.beneficiaries(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
h.Renderer.CreateGroup(w, r, Depart, Arrive, searched, beneficiary, accountsBeneficaire, departurgeo, dstinationgeo)
|
||||
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
groupid := vars["groupid"]
|
||||
|
||||
request := &groupsmanagement.GetGroupRequest{
|
||||
Id: groupid,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var accounts = []any{}
|
||||
|
||||
requesst := &mobilityaccounts.GetAccountsBatchRequest{
|
||||
Accountids: resp.Group.Members,
|
||||
}
|
||||
|
||||
ressp, _ := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), requesst)
|
||||
|
||||
for _, account := range ressp.Accounts {
|
||||
if filterAcc(r, account) {
|
||||
a := account.ToStorageType()
|
||||
accounts = append(accounts, a)
|
||||
}
|
||||
}
|
||||
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||
r.ParseForm()
|
||||
|
||||
var beneficiary any
|
||||
searched := false
|
||||
|
||||
if r.FormValue("beneficiaryid") != "" {
|
||||
|
||||
searched = true
|
||||
|
||||
requestbeneficiary := &mobilityaccounts.GetAccountRequest{
|
||||
Id: r.FormValue("beneficiaryid"),
|
||||
}
|
||||
|
||||
respbeneficiary, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), requestbeneficiary)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiary = respbeneficiary.Account.ToStorageType()
|
||||
|
||||
subscribe := &groupsmanagement.SubscribeRequest{
|
||||
Groupid: resp.Group.ToStorageType().ID,
|
||||
Memberid: respbeneficiary.Account.Id,
|
||||
}
|
||||
|
||||
_, err = h.services.GRPC.GroupsManagement.Subscribe(context.TODO(), subscribe)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
/*******************Code to store more information about mermbers groupscovoiturage**************/
|
||||
if r.FormValue("departure") != "" {
|
||||
var a any
|
||||
json.Unmarshal([]byte(r.FormValue("departure")), &a)
|
||||
|
||||
Depart = a
|
||||
}
|
||||
if r.FormValue("destination") != "" {
|
||||
var a any
|
||||
json.Unmarshal([]byte(r.FormValue("destination")), &a)
|
||||
|
||||
Arrive = a
|
||||
}
|
||||
r.ParseForm()
|
||||
dataMap := map[string]any{
|
||||
|
||||
"depart": Depart,
|
||||
"arrive": Arrive,
|
||||
}
|
||||
id := uuid.NewString()
|
||||
data, err := structpb.NewValue(dataMap)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
request_organizatio := &groupsmanagement.AddGroupMemberRequest{
|
||||
Group: &groupsmanagement.GroupMember{
|
||||
Id: id,
|
||||
Memberid: respbeneficiary.Account.Id,
|
||||
Groupid: resp.Group.ToStorageType().ID,
|
||||
Data: data.GetStructValue(),
|
||||
},
|
||||
}
|
||||
|
||||
_, err = h.services.GRPC.GroupsManagement.AddGroupMember(context.TODO(), request_organizatio)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", resp.Group.ToStorageType().ID), http.StatusFound)
|
||||
return
|
||||
}
|
||||
//////////find all groups to store the adresse passenger///////
|
||||
// grp := &groupsmanagement.GetGroupsBatchMemberRequest{
|
||||
|
||||
// Groupids: []string{resp.Group.ToStorageType().ID},
|
||||
// }
|
||||
// s, err := h.services.GRPC.GroupsManagement.GetGroupsBatchMember(context.TODO(), grp)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// groups := map[string]any{}
|
||||
|
||||
// if err == nil {
|
||||
// for _, g := range s.Groups {
|
||||
// groups[g.Memberid] = g.ToStorageType()
|
||||
// }
|
||||
// }
|
||||
//////////find all groups to store the adresse passenger///////
|
||||
///////////try to optimise the code ////////////////////////////
|
||||
groups, _ := h.services.GetGroupsMemberMap(resp.Group.ToStorageType().ID)
|
||||
//fmt.Println(groups)
|
||||
var number string = strconv.Itoa(len(resp.Group.Members))
|
||||
/////////////////////
|
||||
accountsBeneficaire, err := h.beneficiaries(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
h.Renderer.DisplayGroupCovoiturage(w, r, number, resp.Group.ToStorageType().ID, Depart, Arrive, accounts, cacheid, searched, beneficiary, resp.Group.ToStorageType(), accountsBeneficaire, groups)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) UpdateGroupCovoiturage(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
id := vars["id"]
|
||||
groupid := vars["groupid"]
|
||||
memberid := vars["memberid"]
|
||||
|
||||
if r.Method == "POST" {
|
||||
|
||||
//////////get groupid covoiturage//////////
|
||||
request := &groupsmanagement.GetGroupRequest{
|
||||
Id: groupid,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
//////////////////////////get group member////////////////////////////////
|
||||
|
||||
reequest := &groupsmanagement.GetGroupMemberRequest{
|
||||
Id: id,
|
||||
}
|
||||
|
||||
ressp, err := h.services.GRPC.GroupsManagement.GetGroupMember(context.TODO(), reequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
req := &groupsmanagement.UnsubscribeMemberRequest{
|
||||
Id: ressp.Group.Id,
|
||||
}
|
||||
|
||||
_, errr := h.services.GRPC.GroupsManagement.UnsubscribeMember(context.TODO(), req)
|
||||
if errr != nil {
|
||||
fmt.Println(errr)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
members := resp.Group.Members
|
||||
for i := 0; i < len(members); i++ {
|
||||
if members[i] == memberid {
|
||||
members = append(members[:i], members[(i+1):]...)
|
||||
resp.Group.Members = members
|
||||
reequest := &groupsmanagement.UnsubscribeRequest{
|
||||
Groupid: resp.Group.ToStorageType().ID,
|
||||
Memberid: memberid,
|
||||
}
|
||||
|
||||
_, err := h.services.GRPC.GroupsManagement.Unsubscribe(context.TODO(), reequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/journeys/groups_covoiturage/create/%s", groupid), http.StatusFound)
|
||||
/*
|
||||
I must add "return" to resolve the err
|
||||
http: superfluous response.WriteHeader call from git.coopgo.io/coopgo-apps/parcoursmob/renderer.(*Renderer).Render (renderer.go:50)
|
||||
*/
|
||||
return
|
||||
}
|
||||
h.Renderer.UpdateGroupCovoiturage(w, r, groupid, memberid)
|
||||
}
|
||||
|
||||
@@ -6,9 +6,12 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
"github.com/google/uuid"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
@@ -16,7 +19,7 @@ type UserForm struct {
|
||||
FirstName string `json:"first_name" validate:"required"`
|
||||
LastName string `json:"last_name" validate:"required"`
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
PhoneNumber string `json:"phone_number" validate:"required,phoneNumber"`
|
||||
PhoneNumber string `json:"phone_number" `
|
||||
Address any `json:"address,omitempty"`
|
||||
Gender string `json:"gender"`
|
||||
}
|
||||
@@ -36,8 +39,34 @@ func (h *ApplicationHandler) MemberDisplay(w http.ResponseWriter, r *http.Reques
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
//////////////////////////////////add organisations/////////////////////////////////////////////////
|
||||
|
||||
h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType())
|
||||
var allIds []string
|
||||
for _, v := range resp.Account.ToStorageType().Data["groups"].([]any) {
|
||||
s := fmt.Sprintf("%v", v)
|
||||
if !(strings.Contains(s, "admin")) {
|
||||
allIds = append(allIds, s)
|
||||
}
|
||||
}
|
||||
reques := &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: allIds,
|
||||
}
|
||||
|
||||
res, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), reques)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var groupsName []string
|
||||
|
||||
for _, group := range res.Groups {
|
||||
g := fmt.Sprintf("%v", group.ToStorageType().Data["name"])
|
||||
groupsName = append(groupsName, g)
|
||||
}
|
||||
|
||||
h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType(), groupsName)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -126,3 +155,59 @@ func parseUserForm(r *http.Request) (map[string]any, error) {
|
||||
|
||||
return dataMap, nil
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) MembersList(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
accounts, err := h.services.GetAccounts()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
var groupsName []string
|
||||
|
||||
for _, v := range accounts {
|
||||
adminid := v.ID
|
||||
request := &mobilityaccounts.GetAccountRequest{
|
||||
Id: adminid,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
//////////////////////////////////add organisations/////////////////////////////////////////////////
|
||||
|
||||
var allIds []string
|
||||
for _, v := range resp.Account.ToStorageType().Data["groups"].([]any) {
|
||||
s := fmt.Sprintf("%v", v)
|
||||
if !(strings.Contains(s, "admin")) {
|
||||
allIds = append(allIds, s)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
reques := &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: allIds,
|
||||
}
|
||||
|
||||
res, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), reques)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
g := ""
|
||||
for _, group := range res.Groups {
|
||||
g += fmt.Sprintf("%v", group.ToStorageType().Data["name"]) + " "
|
||||
}
|
||||
groupsName = append(groupsName, g)
|
||||
|
||||
}
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||
|
||||
h.Renderer.MembersList(w, r, accounts, cacheid, groupsName)
|
||||
}
|
||||
|
||||
@@ -42,20 +42,26 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
|
||||
for _, vehicle := range resp.Vehicles {
|
||||
if filterVehicle(r, vehicle) {
|
||||
v := vehicle.ToStorageType()
|
||||
vehicles = append(vehicles, v)
|
||||
vehicles_map[v.ID] = v
|
||||
vehicleBookings := []fleetsstorage.Booking{}
|
||||
for _, b := range v.Bookings {
|
||||
if b.Status() != fleetsstorage.StatusOld {
|
||||
bookings = append(bookings, b)
|
||||
if deleted, ok := b.Data["Deleted"].(bool); !ok && !deleted {
|
||||
bookings = append(bookings, b)
|
||||
}
|
||||
}
|
||||
if b.Unavailableto.After(time.Now()) {
|
||||
vehicleBookings = append(vehicleBookings, b)
|
||||
}
|
||||
}
|
||||
v.Bookings = vehicleBookings
|
||||
vehicles = append(vehicles, v)
|
||||
vehicles_map[v.ID] = v
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||
|
||||
h.Renderer.VehiclesManagementOverview(w, r, vehicles, vehicles_map, bookings)
|
||||
}
|
||||
|
||||
@@ -188,29 +194,6 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http
|
||||
h.Renderer.VehiclesFleetDisplay(w, r, resp.Vehicle.ToStorageType())
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
vehicleid := vars["vehicleid"]
|
||||
|
||||
if r.Method == "POST" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
request := &fleets.GetVehicleRequest{
|
||||
Vehicleid: vehicleid,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType())
|
||||
}
|
||||
|
||||
func filterVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
@@ -320,6 +303,8 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
|
||||
|
||||
alternativerequest := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
Types: []string{booking.Vehicle.Type},
|
||||
Administrators: booking.Vehicle.Administrators,
|
||||
AvailabilityFrom: timestamppb.New(booking.Startdate),
|
||||
AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)),
|
||||
}
|
||||
@@ -457,3 +442,211 @@ func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter,
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", vehicleid), http.StatusFound)
|
||||
}
|
||||
|
||||
// func (h *ApplicationHandler) UnbookingVehicles(w http.ResponseWriter, r *http.Request) {
|
||||
// request := &fleets.GetVehiclesRequest{
|
||||
// Namespaces: []string{"parcoursmob"},
|
||||
// }
|
||||
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// }
|
||||
// vehicles := []fleetsstorage.Vehicle{}
|
||||
// fmt.Println(resp.Vehicles[0].Bookings)
|
||||
// for i, vehicle := range resp.Vehicles {
|
||||
// if len(resp.Vehicles[i].Bookings) == 0 {
|
||||
// v := vehicle.ToStorageType()
|
||||
// vehicles = append(vehicles, v)
|
||||
// }
|
||||
// }
|
||||
// // if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
|
||||
// // h.Renderer.UnbookingVehicles(w, r, resp.Vehicle.ToStorageType())
|
||||
// // }
|
||||
// // fmt.Println(resp.Vehicle.ToStorageType().Bookings)
|
||||
// fmt.Println(vehicles)
|
||||
// h.Renderer.UnbookingVehicles(w, r, vehicles)
|
||||
// }
|
||||
func (h *ApplicationHandler) UnbookingVehicle(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
bookingid := vars["bookingid"]
|
||||
|
||||
request := &fleets.GetBookingRequest{
|
||||
Bookingid: bookingid,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.GetBooking(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
date := now.Format("2006-01-02")
|
||||
unavailableto, _ := time.Parse("2006-01-02", date)
|
||||
|
||||
current_group, err := h.currentGroup(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
current_user_token, current_user_claims, err := h.currentUser(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
booked_by_id := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
|
||||
booked_by_name := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
|
||||
booked_by_email := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
|
||||
booked_by_group_id := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
|
||||
booked_by_group_name := resp.Booking.Data.Fields["booked_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
|
||||
|
||||
data := map[string]any{
|
||||
"booked_by": map[string]any{
|
||||
"user": map[string]any{
|
||||
"id": booked_by_id,
|
||||
"display_name": booked_by_name,
|
||||
"email": booked_by_email,
|
||||
},
|
||||
"group": map[string]any{
|
||||
"id": booked_by_group_id,
|
||||
"name": booked_by_group_name,
|
||||
},
|
||||
},
|
||||
"unbooked_by": map[string]any{
|
||||
"user": map[string]any{
|
||||
"id": current_user_token.Subject,
|
||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
||||
"email": current_user_claims["email"],
|
||||
},
|
||||
"group": map[string]any{
|
||||
"id": current_group.ID,
|
||||
"name": current_group.Data["name"],
|
||||
},
|
||||
},
|
||||
"Deleted": true,
|
||||
"motif": r.FormValue("motif"),
|
||||
}
|
||||
|
||||
datapb, err := structpb.NewStruct(data)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if r.Method == "POST" {
|
||||
|
||||
request := &fleets.UpdateBookingRequest{
|
||||
Booking: &fleets.Booking{
|
||||
Id: resp.Booking.Id,
|
||||
Vehicleid: resp.Booking.Vehicleid,
|
||||
Driver: resp.Booking.Driver,
|
||||
Startdate: resp.Booking.Startdate,
|
||||
Enddate: resp.Booking.Enddate,
|
||||
Unavailablefrom: resp.Booking.Unavailablefrom,
|
||||
Unavailableto: timestamppb.New(unavailableto),
|
||||
Data: datapb,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/app/vehicles-management/", http.StatusFound)
|
||||
return
|
||||
}
|
||||
h.Renderer.UnbookingVehicle(w, r, resp.Booking.ToStorageType())
|
||||
}
|
||||
|
||||
////////////////////////UpdateVehicle///////////////////////
|
||||
|
||||
func (h *ApplicationHandler) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
vehicleID := vars["vehicleid"]
|
||||
request := &fleets.GetVehicleRequest{
|
||||
Vehicleid: vehicleID,
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.GetVehicle(context.TODO(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
namespaceV := resp.Vehicle.Namespace
|
||||
//typeV := resp.Vehicle.Type
|
||||
administratorsV := resp.Vehicle.Administrators
|
||||
|
||||
if r.Method == "POST" {
|
||||
fmt.Print(r.FormValue("vehicle_type"))
|
||||
if err := r.ParseForm(); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
dataMap := map[string]any{}
|
||||
if v := r.FormValue("name"); v != "" {
|
||||
dataMap["name"] = v
|
||||
}
|
||||
if v := r.FormValue("address"); v != "" {
|
||||
var address map[string]any
|
||||
err := json.Unmarshal([]byte(v), &address)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
dataMap["address"] = address
|
||||
}
|
||||
if v := r.FormValue("informations"); v != "" {
|
||||
dataMap["informations"] = v
|
||||
}
|
||||
if v := r.FormValue("licence_plate"); v != "" {
|
||||
dataMap["licence_plate"] = v
|
||||
}
|
||||
if v := r.FormValue("automatic"); v != "" {
|
||||
fmt.Println(v)
|
||||
dataMap["automatic"] = (v == "on")
|
||||
}
|
||||
|
||||
data, err := structpb.NewValue(dataMap)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
request := &fleets.UpdateVehicleRequest{
|
||||
Vehicle: &fleets.Vehicle{
|
||||
Id: vehicleID,
|
||||
Namespace: namespaceV,
|
||||
Type: r.FormValue("type"),
|
||||
Administrators: administratorsV,
|
||||
Data: data.GetStructValue(),
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := h.services.GRPC.Fleets.UpdateVehicle(context.TODO(), request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/fleet/%s", resp.Vehicle.Id), http.StatusFound)
|
||||
return
|
||||
}
|
||||
vehicles_types := h.config.GetStringSlice("modules.fleets.vehicle_types")
|
||||
h.Renderer.VehiclesFleetUpdate(w, r, resp.Vehicle.ToStorageType(), vehicles_types)
|
||||
}
|
||||
|
||||
196
handlers/exports/agenda.go
Normal file
196
handlers/exports/agenda.go
Normal file
@@ -0,0 +1,196 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
accountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"net/http"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func (h *ExportsHandler) Agenda(filter string) func(w http.ResponseWriter, r *http.Request) {
|
||||
switch filter {
|
||||
case "allEvents":
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
events := []agendastorage.Event{}
|
||||
|
||||
groupids := []string{}
|
||||
beneficiaries_ids := []string{}
|
||||
for _, e := range resp.Events {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
events = append(events, e.ToStorageType())
|
||||
|
||||
for _, subscriptions := range e.Subscriptions {
|
||||
beneficiaries_ids = append(beneficiaries_ids, subscriptions.Subscriber)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(events))
|
||||
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]groupsstorage.Group{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||
Accountids: beneficiaries_ids,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_map := map[string]accountsstorage.Account{}
|
||||
for _, ben := range beneficiaries.Accounts {
|
||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||
}
|
||||
|
||||
f := h.generateExcel(events, groups, beneficiaries_map)
|
||||
|
||||
h.writeFileResponse(f, w)
|
||||
}
|
||||
|
||||
case "oneEvent":
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
eventId := vars["eventid"]
|
||||
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), &agenda.GetEventRequest{
|
||||
Id: eventId,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
groupids := []string{}
|
||||
beneficiaries_ids := []string{}
|
||||
groupids = append(groupids, resp.Event.Owners...)
|
||||
for _, subscriptions := range resp.Event.Subscriptions {
|
||||
beneficiaries_ids = append(beneficiaries_ids, subscriptions.Subscriber)
|
||||
}
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]groupsstorage.Group{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||
Accountids: beneficiaries_ids,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_map := map[string]accountsstorage.Account{}
|
||||
for _, ben := range beneficiaries.Accounts {
|
||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||
}
|
||||
|
||||
f := h.generateExcel([]agendastorage.Event{resp.Event.ToStorageType()}, groups, beneficiaries_map)
|
||||
h.writeFileResponse(f, w)
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ExportsHandler) generateExcel(events []agendastorage.Event, groups map[string]groupsstorage.Group,
|
||||
beneficiaries_map map[string]accountsstorage.Account) *excelize.File {
|
||||
f := excelize.NewFile()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
f.SetCellValue("Sheet1", "A1", "Evénement")
|
||||
f.SetCellValue("Sheet1", "B1", "Date de début")
|
||||
f.SetCellValue("Sheet1", "C1", "Date de fin")
|
||||
f.SetCellValue("Sheet1", "D1", "Nom bénéficiaire")
|
||||
f.SetCellValue("Sheet1", "E1", "Prenom bénéficiaire")
|
||||
f.SetCellValue("Sheet1", "F1", "Numéro allocataire / Pole emploi")
|
||||
f.SetCellValue("Sheet1", "G1", "Prescipteur")
|
||||
f.SetCellValue("Sheet1", "H1", "Prescipteur Nom")
|
||||
f.SetCellValue("Sheet1", "I1", "Gestionnaire événement")
|
||||
i := 2
|
||||
for _, e := range events {
|
||||
if len(e.Owners) == 0 {
|
||||
continue
|
||||
}
|
||||
admin := groups[e.Owners[0]]
|
||||
|
||||
subscribedbygroup := ""
|
||||
subscribedbyuser := ""
|
||||
if v, ok := e.Data["subscribed_by"].(map[string]any); ok {
|
||||
if v2, ok := v["group"].(map[string]any); ok {
|
||||
if v3, ok := v2["id"].(string); ok {
|
||||
subscribedbygroup = v3
|
||||
}
|
||||
|
||||
}
|
||||
if v4, ok := v["user"].(map[string]any); ok {
|
||||
if v5, ok := v4["display_name"].(string); ok {
|
||||
subscribedbyuser = v5
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range e.Subscriptions {
|
||||
|
||||
beneficiary := beneficiaries_map[s.Subscriber]
|
||||
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("A%d", i), e.Name)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("B%d", i), e.Startdate.Format("2006-01-02"))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("C%d", i), e.Enddate.Format("2006-01-02"))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("D%d", i), beneficiary.Data["last_name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("E%d", i), beneficiary.Data["first_name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("F%d", i), beneficiary.Data["file_number"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("G%d", i), groups[subscribedbygroup].Data["name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("H%d", i), subscribedbyuser)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("I%d", i), admin.Data["name"])
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
}
|
||||
return f
|
||||
|
||||
}
|
||||
|
||||
func (h *ExportsHandler) writeFileResponse(file *excelize.File, w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
|
||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
w.Header().Set("Expires", "0")
|
||||
file.Write(w)
|
||||
}
|
||||
21
handlers/exports/exports.go
Normal file
21
handlers/exports/exports.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
||||
"git.coopgo.io/coopgo-platform/emailing"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type ExportsHandler struct {
|
||||
config *viper.Viper
|
||||
services *services.ServicesHandler
|
||||
emailing *emailing.Mailer
|
||||
}
|
||||
|
||||
func NewExportsHandler(cfg *viper.Viper, svc *services.ServicesHandler, emailing *emailing.Mailer) (*ExportsHandler, error) {
|
||||
return &ExportsHandler{
|
||||
config: cfg,
|
||||
services: svc,
|
||||
emailing: emailing,
|
||||
}, nil
|
||||
}
|
||||
163
handlers/exports/fleets.go
Normal file
163
handlers/exports/fleets.go
Normal file
@@ -0,0 +1,163 @@
|
||||
package exports
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
accountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
vehicles := map[string]fleetsstorage.Vehicle{}
|
||||
bookings := []fleetsstorage.Booking{}
|
||||
reequest := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
}
|
||||
reesp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), reequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_ids := []string{}
|
||||
|
||||
for _, vehicle := range reesp.Vehicles {
|
||||
|
||||
v := vehicle.ToStorageType()
|
||||
fmt.Println(v)
|
||||
|
||||
for _, b := range v.Bookings {
|
||||
bookings = append(bookings, b)
|
||||
beneficiaries_ids = append(beneficiaries_ids, b.Driver)
|
||||
}
|
||||
|
||||
vehicles[vehicle.Id] = v
|
||||
|
||||
}
|
||||
|
||||
|
||||
groups := map[string]groupsstorage.Group{}
|
||||
|
||||
admingroups, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), &groupsmanagement.GetGroupsRequest{
|
||||
Namespaces: []string{"parcoursmob_organizations"},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, g := range admingroups.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(context.TODO(), &accounts.GetAccountsBatchRequest{
|
||||
Accountids: beneficiaries_ids,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries_map := map[string]accountsstorage.Account{}
|
||||
for _, ben := range beneficiaries.Accounts {
|
||||
beneficiaries_map[ben.Id] = ben.ToStorageType()
|
||||
}
|
||||
|
||||
/////////////// Generate file
|
||||
|
||||
f := excelize.NewFile()
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}()
|
||||
|
||||
f.SetCellValue("Sheet1", "A1", "Numéro")
|
||||
f.SetCellValue("Sheet1", "B1", "Type")
|
||||
f.SetCellValue("Sheet1", "C1", "Gestionnaire")
|
||||
f.SetCellValue("Sheet1", "D1", "Prescripteur")
|
||||
f.SetCellValue("Sheet1", "E1", "Bénéficiaire")
|
||||
f.SetCellValue("Sheet1", "F1", "Numéro allocataire / Pole emploi")
|
||||
f.SetCellValue("Sheet1", "G1", "Début de Mise à disposition")
|
||||
f.SetCellValue("Sheet1", "H1", "Fin de mise Ă disposition")
|
||||
f.SetCellValue("Sheet1", "I1", "Début indisponibilité")
|
||||
f.SetCellValue("Sheet1", "J1", "Fin indisponibilité")
|
||||
f.SetCellValue("Sheet1", "K1", "Retrait par le gestionnaire")
|
||||
f.SetCellValue("Sheet1", "L1", "Commentaire")
|
||||
|
||||
i := 2
|
||||
for _, b := range bookings {
|
||||
vehicle := vehicles[b.Vehicleid]
|
||||
if len(vehicle.Administrators) == 0 {
|
||||
continue
|
||||
}
|
||||
admin := groups[vehicle.Administrators[0]]
|
||||
|
||||
bookedby := ""
|
||||
if v, ok := b.Data["booked_by"].(map[string]any); ok {
|
||||
if v2, ok := v["user"].(map[string]any); ok {
|
||||
if v3, ok := v2["display_name"].(string); ok {
|
||||
bookedby = v3
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bookedbygroup := ""
|
||||
if v4, ok := b.Data["booked_by"].(map[string]any); ok {
|
||||
if v5, ok := v4["group"].(map[string]any); ok {
|
||||
if v6, ok := v5["id"].(string); ok {
|
||||
bookedbygroup = v6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// filter by group
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
group := g.(groupsstorage.Group)
|
||||
|
||||
if bookedbygroup != group.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
beneficiary := beneficiaries_map[b.Driver]
|
||||
adminunavailability := false
|
||||
|
||||
if av, ok := b.Data["administrator_unavailability"].(bool); ok && av {
|
||||
adminunavailability = true
|
||||
}
|
||||
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("A%d", i), vehicle.Data["licence_plate"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("B%d", i), vehicle.Type)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("C%d", i), admin.Data["name"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("D%d", i), bookedby)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("E%d", i), fmt.Sprintf("%v %v", beneficiary.Data["first_name"], beneficiary.Data["last_name"]))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("F%d", i), beneficiary.Data["file_number"])
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("G%d", i), b.Startdate.Format("2006-01-02"))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("H%d", i), b.Enddate.Format("2006-01-02"))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("I%d", i), b.Unavailablefrom.Format("2006-01-02"))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("J%d", i), b.Unavailableto.Format("2006-01-02"))
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("K%d", i), adminunavailability)
|
||||
f.SetCellValue("Sheet1", fmt.Sprintf("L%d", i), b.Data["comment"])
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename="+"Workbook.xlsx")
|
||||
w.Header().Set("Content-Transfer-Encoding", "binary")
|
||||
w.Header().Set("Expires", "0")
|
||||
f.Write(w)
|
||||
|
||||
}
|
||||
36
main.go
36
main.go
@@ -9,6 +9,7 @@ import (
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/api"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/application"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/auth"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/exports"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
@@ -26,6 +27,7 @@ func main() {
|
||||
address = cfg.GetString("server.listen")
|
||||
service_name = cfg.GetString("service_name")
|
||||
templates_public_dir = cfg.GetString("templates.public_dir")
|
||||
dev_env = cfg.GetBool("dev_env")
|
||||
)
|
||||
|
||||
svc, err := services.NewServicesHandler(cfg)
|
||||
@@ -52,9 +54,13 @@ func main() {
|
||||
|
||||
apiHandler, _ := api.NewAPIHandler(cfg, idp, svc, kv)
|
||||
applicationHandler, _ := application.NewApplicationHandler(cfg, svc, kv, filestorage, emailing)
|
||||
exportsHandler, _ := exports.NewExportsHandler(cfg, svc, emailing)
|
||||
authHandler, _ := auth.NewAuthHandler(cfg, idp, svc, kv, emailing)
|
||||
|
||||
fmt.Println("Running", service_name, ":")
|
||||
if dev_env {
|
||||
fmt.Printf("\033]0;%s\007", service_name)
|
||||
}
|
||||
|
||||
r := mux.NewRouter()
|
||||
|
||||
@@ -87,6 +93,7 @@ func main() {
|
||||
application.HandleFunc("/members/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
||||
application.HandleFunc("/members/{adminid}", applicationHandler.MemberDisplay)
|
||||
application.HandleFunc("/members/{adminid}/update", applicationHandler.MemberUpdate)
|
||||
application.HandleFunc("/members/", applicationHandler.MembersList)
|
||||
application.HandleFunc("/journeys/", applicationHandler.JourneysSearch)
|
||||
application.HandleFunc("/vehicles/", applicationHandler.VehiclesSearch)
|
||||
application.HandleFunc("/vehicles/bookings/", applicationHandler.VehiclesBookingsList)
|
||||
@@ -100,8 +107,13 @@ func main() {
|
||||
application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate)
|
||||
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
|
||||
/////////////////////////////////////Remove booking vehicle/////////////////////////////////////////
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/delete", applicationHandler.UnbookingVehicle)
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
|
||||
application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
|
||||
application.HandleFunc("/agenda/history", applicationHandler.AgendaHistory)
|
||||
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)
|
||||
application.HandleFunc("/agenda/{eventid}", applicationHandler.AgendaDisplayEvent)
|
||||
///////////////////////////////Code to modify event///////////////////////
|
||||
@@ -116,9 +128,10 @@ func main() {
|
||||
application.HandleFunc("/group/settings/invite-member", applicationHandler.GroupSettingsInviteMember)
|
||||
|
||||
/****************************Groupe Déplacement ************************************/
|
||||
// application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
||||
// application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
||||
// application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
||||
application.HandleFunc("/journeys/groups_covoiturage", applicationHandler.GroupsGestion)
|
||||
application.HandleFunc("/journeys/groups_covoiturage/create", applicationHandler.CreateGroup)
|
||||
application.HandleFunc("/journeys/groups_covoiturage/create/{groupid}", applicationHandler.DisplayGroupCovoiturage)
|
||||
application.HandleFunc("/journeys/groups_covoiturage/create/{id}/{groupid}/{memberid}", applicationHandler.UpdateGroupCovoiturage)
|
||||
/****************************************************************/
|
||||
|
||||
/********************Code Supprt Emailing************************/
|
||||
@@ -140,7 +153,24 @@ func main() {
|
||||
appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay)
|
||||
appAdmin.HandleFunc("/groups/{groupid}/invite-admin", applicationHandler.AdministrationGroupInviteAdmin)
|
||||
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
||||
//add statistiques
|
||||
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
|
||||
appAdmin.HandleFunc("/stats/bookings", applicationHandler.AdminStatBookings)
|
||||
appAdmin.HandleFunc("/stats/beneficaires", applicationHandler.AdminStatBeneficaires)
|
||||
appAdmin.HandleFunc("/stats/events", applicationHandler.AdminStatEvents)
|
||||
|
||||
/////////////////////////////////////Delete subscriber///////////////////////////////////////////////
|
||||
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
||||
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
export := r.PathPrefix("/exports").Subrouter()
|
||||
export.HandleFunc("/fleets/bookings", exportsHandler.Bookings)
|
||||
export.HandleFunc("/fleets/bookings/{groupid}", exportsHandler.Bookings)
|
||||
export.HandleFunc("/agenda/subscriptions", exportsHandler.Agenda("allEvents"))
|
||||
export.HandleFunc("/agenda/{eventid}", exportsHandler.Agenda("oneEvent"))
|
||||
export.Use(idp.Middleware)
|
||||
export.Use(idp.GroupsMiddleware)
|
||||
|
||||
fmt.Println("-> HTTP server listening on", address)
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package renderer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
)
|
||||
|
||||
const administrationMenu = "administration"
|
||||
|
||||
func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, accounts any, beneficiaries any, groups any, bookings any) {
|
||||
func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, accounts any, beneficiaries any, groups any, bookings any, events []agendastorage.Event) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.administration.home.files")
|
||||
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||
state.ViewState = map[string]any{
|
||||
@@ -16,6 +20,7 @@ func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request,
|
||||
"beneficiaries": beneficiaries,
|
||||
"bookings": bookings,
|
||||
"groups": groups,
|
||||
"events": events,
|
||||
}
|
||||
|
||||
renderer.Render("administration", w, r, files, state)
|
||||
@@ -39,3 +44,71 @@ func (renderer *Renderer) AdministrationGroupDisplay(w http.ResponseWriter, r *h
|
||||
|
||||
renderer.Render("administration", w, r, files, state)
|
||||
}
|
||||
|
||||
type BeneficiariesState struct {
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||
}
|
||||
|
||||
func (s BeneficiariesState) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s BeneficiariesState) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < len(s.Beneficiaries) {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request, Beneficiaries []mobilityaccountsstorage.Account, cacheid string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.administration.beneficaires_list.files")
|
||||
|
||||
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||
state.ViewState = BeneficiariesState{
|
||||
Count: len(Beneficiaries),
|
||||
CacheId: cacheid,
|
||||
Beneficiaries: Beneficiaries,
|
||||
}
|
||||
|
||||
renderer.Render("beneficiaries_State", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) AdminStatEvents(w http.ResponseWriter, r *http.Request, events []agendastorage.Event, groups map[string]any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.administration.events_list.files")
|
||||
|
||||
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"events": events,
|
||||
"groups": groups,
|
||||
}
|
||||
|
||||
renderer.Render("beneficiaries_State", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) AdminStatVehicles(w http.ResponseWriter, r *http.Request, vehicles []fleetsstorage.Vehicle, bookings []fleetsstorage.Booking, admingroups map[string]any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.administration.vehicles_list.files")
|
||||
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"vehicles": vehicles,
|
||||
"bookings": bookings,
|
||||
"admingroups": admingroups,
|
||||
}
|
||||
|
||||
renderer.Render("vehicles_state", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) AdminStatBookings(w http.ResponseWriter, r *http.Request, vehicles map[string]fleetsstorage.Vehicle, bookings []fleetsstorage.Booking, admingroups map[string]any, beneficiaries map[string]any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.administration.bookings_list.files")
|
||||
state := NewState(r, renderer.ThemeConfig, administrationMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"vehicles_map": vehicles,
|
||||
"bookings": bookings,
|
||||
"admingroups": admingroups,
|
||||
"beneficiaries_map": beneficiaries,
|
||||
}
|
||||
|
||||
renderer.Render("bookings_stats", w, r, files, state)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,17 @@ func (renderer *Renderer) AgendaHome(w http.ResponseWriter, r *http.Request, eve
|
||||
renderer.Render("agenda home", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) AgendaHistory(w http.ResponseWriter, r *http.Request, events []agendastorage.Event, groups map[string]any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.history.files")
|
||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"events": events,
|
||||
"groups": groups,
|
||||
}
|
||||
|
||||
renderer.Render("agenda history", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) AgendaCreateEvent(w http.ResponseWriter, r *http.Request) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.create_event.files")
|
||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
@@ -40,6 +51,34 @@ func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Requ
|
||||
renderer.Render("agenda create event", w, r, files, state)
|
||||
}
|
||||
|
||||
//////////////////////////DElete subscriber//////////////////////////////////
|
||||
func (renderer *Renderer) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request, eventid string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.delete_subscriber.files")
|
||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"eventid": eventid,
|
||||
}
|
||||
|
||||
renderer.Render("agenda delete subscriber", w, r, files, state)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////History Event//////////////////////////////////
|
||||
func (renderer *Renderer) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request, event any, group any, subscribers map[string]any, beneficiaries any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.history_event.files")
|
||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"event": event,
|
||||
"group": group,
|
||||
"subscribers": subscribers,
|
||||
"beneficiaries": beneficiaries,
|
||||
}
|
||||
|
||||
renderer.Render("agenda history event", w, r, files, state)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
func (renderer *Renderer) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request, event any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.update.files")
|
||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package renderer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitlab.scity.coop/maas/navitia-golang/types"
|
||||
@@ -67,6 +69,22 @@ func JSON(v any) template.JS {
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func RawJSON(v any) string {
|
||||
buf := new(bytes.Buffer)
|
||||
enc := json.NewEncoder(buf)
|
||||
enc.SetEscapeHTML(false)
|
||||
err := enc.Encode(&v)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSuffix(buf.String(), "\n")
|
||||
|
||||
}
|
||||
|
||||
func UnescapeHTML(s string) template.HTML {
|
||||
return template.HTML(s)
|
||||
}
|
||||
|
||||
func Dict(v ...interface{}) map[string]interface{} {
|
||||
dict := map[string]interface{}{}
|
||||
lenv := len(v)
|
||||
|
||||
@@ -1,9 +1,40 @@
|
||||
package renderer
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
)
|
||||
|
||||
const journeysMenu = "journeys"
|
||||
|
||||
type BeneficiariesCovoiturage struct {
|
||||
Group string `json:"group"`
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
Beneficiaries []any `json:"beneficiaries"`
|
||||
}
|
||||
type BeneficiariesCovoiturageA struct {
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
Beneficiaries []any `json:"beneficiaries"`
|
||||
}
|
||||
|
||||
func (s BeneficiariesCovoiturage) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s BeneficiariesCovoiturage) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < len(s.Beneficiaries) {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, transitjourneys any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files")
|
||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||
@@ -20,3 +51,100 @@ func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request,
|
||||
|
||||
renderer.Render("journeys", w, r, files, state)
|
||||
}
|
||||
|
||||
type BeneficiariesListstate struct {
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
Beneficiaries []groupstorage.Group `json:"beneficiaries"`
|
||||
}
|
||||
|
||||
func (s BeneficiariesListstate) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s BeneficiariesListstate) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < len(s.Beneficiaries) {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
func (renderer *Renderer) GroupsGestion(w http.ResponseWriter, r *http.Request, groups []groupstorage.Group, cacheid string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.list.files")
|
||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||
|
||||
state.ViewState = BeneficiariesListstate{
|
||||
Count: len(groups),
|
||||
CacheId: cacheid,
|
||||
Beneficiaries: groups,
|
||||
}
|
||||
|
||||
renderer.Render("journeys", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) CreateGroup(w http.ResponseWriter, r *http.Request, depart any, arrive any, searched bool, beneficiary any, beneficiaries []mobilityaccountsstorage.Account, departure any, destination any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.create.files")
|
||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||
viewstate := map[string]any{
|
||||
"deeparture": depart,
|
||||
"deestination": arrive,
|
||||
"beneficiaries": beneficiaries,
|
||||
"searched": searched,
|
||||
"departure": departure,
|
||||
"destination": destination,
|
||||
}
|
||||
|
||||
if searched {
|
||||
viewstate["search"] = map[string]any{
|
||||
"beneficiary": beneficiary,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
state.ViewState = viewstate
|
||||
renderer.Render("journeys", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) DisplayGroupCovoiturage(w http.ResponseWriter, r *http.Request, number string, groupid string, depart any, arrive any, accounts []any, cacheid string, searched bool, beneficiary any, group any, beneficiaries []mobilityaccountsstorage.Account, groups map[string]any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.display.files")
|
||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||
|
||||
viewstate := map[string]any{
|
||||
"beneficiaries": beneficiaries,
|
||||
"searched": searched,
|
||||
"group": group,
|
||||
"deeparture": depart,
|
||||
"deestination": arrive,
|
||||
"groups": groups,
|
||||
"ben": accounts,
|
||||
"number": number,
|
||||
"list": BeneficiariesCovoiturage{
|
||||
Group: groupid,
|
||||
Count: len(accounts),
|
||||
CacheId: cacheid,
|
||||
Beneficiaries: accounts,
|
||||
},
|
||||
}
|
||||
|
||||
if searched {
|
||||
viewstate["search"] = map[string]any{
|
||||
"beneficiary": beneficiary,
|
||||
}
|
||||
|
||||
}
|
||||
state.ViewState = viewstate
|
||||
|
||||
renderer.Render("journeys", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) UpdateGroupCovoiturage(w http.ResponseWriter, r *http.Request, groupid string, memberid string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.journeys.update.files")
|
||||
state := NewState(r, renderer.ThemeConfig, journeysMenu)
|
||||
|
||||
state.ViewState = map[string]any{
|
||||
"groupid": groupid,
|
||||
"memberid": memberid,
|
||||
}
|
||||
renderer.Render("journeys", w, r, files, state)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
package renderer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
)
|
||||
|
||||
const membersMenu = "members"
|
||||
|
||||
func (renderer *Renderer) MemberDisplay(w http.ResponseWriter, r *http.Request, admins any) {
|
||||
func (renderer *Renderer) MemberDisplay(w http.ResponseWriter, r *http.Request, admins any, groups []string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.members.display.files")
|
||||
|
||||
state := NewState(r, renderer.ThemeConfig, membersMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"admins": admins,
|
||||
"groups": groups,
|
||||
}
|
||||
renderer.Render("members_list", w, r, files, state)
|
||||
}
|
||||
@@ -22,3 +27,41 @@ func (renderer *Renderer) MemberUpdate(w http.ResponseWriter, r *http.Request, u
|
||||
state.ViewState = user
|
||||
renderer.Render("members_update", w, r, files, state)
|
||||
}
|
||||
|
||||
type MembersListState struct {
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
Members []mobilityaccountsstorage.Account `json:"members"`
|
||||
Groups []string `json:"groups"`
|
||||
}
|
||||
|
||||
func (s MembersListState) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s MembersListState) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < len(s.Members) {
|
||||
s.Members = s.Members[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) MembersList(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, cacheid string, groups []string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.members.list.files")
|
||||
|
||||
state := NewState(r, renderer.ThemeConfig, membersMenu)
|
||||
|
||||
state.ViewState = map[string]any{
|
||||
|
||||
"list": MembersListState{
|
||||
Count: len(accounts),
|
||||
CacheId: cacheid,
|
||||
Members: accounts,
|
||||
Groups: groups,
|
||||
},
|
||||
"groups": groups,
|
||||
}
|
||||
|
||||
renderer.Render("members_list", w, r, files, state)
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
|
||||
"genderISO5218": GenderISO5218,
|
||||
"dict": Dict,
|
||||
"json": JSON,
|
||||
"rawjson": RawJSON,
|
||||
"unescapeHTML": UnescapeHTML,
|
||||
"walkingLength": WalkingLength,
|
||||
"divideFloat64": Divide[float64],
|
||||
"divideInt": Divide[int],
|
||||
@@ -83,6 +85,8 @@ func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *
|
||||
"genderISO5218": GenderISO5218,
|
||||
"dict": Dict,
|
||||
"json": JSON,
|
||||
"rawjson": RawJSON,
|
||||
"unsescapeHTML": UnescapeHTML,
|
||||
"divideFloat64": Divide[float64],
|
||||
"divideInt": Divide[int],
|
||||
},
|
||||
@@ -156,7 +160,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
||||
Active: menuState == administrationMenu,
|
||||
},
|
||||
|
||||
//TODO from configuration for icons at least
|
||||
MenuItems: []MenuItem{
|
||||
{
|
||||
Title: "Tableau de bord",
|
||||
@@ -212,16 +215,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
||||
})
|
||||
}
|
||||
|
||||
if modules["support"] != nil && modules["support"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Support",
|
||||
Link: "/app/support/",
|
||||
Active: menuState == commentMenu,
|
||||
Icon: "hero:outline/support",
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
if modules["group_module"] != nil && modules["group_module"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Groupes / Communautés",
|
||||
@@ -232,6 +225,16 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
||||
|
||||
}
|
||||
|
||||
if modules["support"] != nil && modules["support"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Support",
|
||||
Link: "/app/support/",
|
||||
Active: menuState == commentMenu,
|
||||
Icon: "hero:outline/support",
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
if modules["directory"] != nil && modules["directory"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Répertoire solutions",
|
||||
|
||||
@@ -53,11 +53,12 @@ func (renderer *Renderer) VehiclesFleetDisplay(w http.ResponseWriter, r *http.Re
|
||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any) {
|
||||
func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Request, vehicle any, vehicle_types []string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.fleet_update.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"vehicle": vehicle,
|
||||
"vehicle": vehicle,
|
||||
"vehicle_types": vehicle_types,
|
||||
}
|
||||
|
||||
renderer.Render("fleet display vehicle", w, r, files, state)
|
||||
@@ -78,3 +79,14 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
|
||||
|
||||
renderer.Render("vehicles search", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) UnbookingVehicle(w http.ResponseWriter, r *http.Request, booking any) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.delete_booking.files")
|
||||
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"booking": booking,
|
||||
}
|
||||
|
||||
renderer.Render("vehicule unbooking", w, r, files, state)
|
||||
|
||||
}
|
||||
@@ -78,3 +78,15 @@ func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Req
|
||||
|
||||
renderer.Render("vehicles search", w, r, files, state)
|
||||
}
|
||||
|
||||
// func (renderer *Renderer) VehicleUnbookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking, vehiclesMap any, groupsMap any) {
|
||||
// files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files")
|
||||
// state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
|
||||
// state.ViewState = map[string]any{
|
||||
// "bookings": bookings,
|
||||
// "vehicles_map": vehiclesMap,
|
||||
// "groups_map": groupsMap,
|
||||
// }
|
||||
|
||||
// renderer.Render("vehicles search", w, r, files, state)
|
||||
// }
|
||||
|
||||
@@ -40,3 +40,19 @@ func (s *ServicesHandler) GetGroupsMap() (groups map[string]storage.Group, err e
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
////////////////////////////////optimize the code//////////////////////////////////////
|
||||
func (s *ServicesHandler) GetGroupsMemberMap(id string) (groups map[string]any, err error) {
|
||||
groups = map[string]any{}
|
||||
|
||||
request := &groupsmanagement.GetGroupsBatchMemberRequest{
|
||||
Groupids: []string{id},
|
||||
}
|
||||
resp, err := s.GRPC.GroupsManagement.GetGroupsBatchMember(context.TODO(), request)
|
||||
if err == nil {
|
||||
for _, group := range resp.Groups {
|
||||
groups[group.Memberid] = group.ToStorageType()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user