Compare commits
44 Commits
main
...
silvermobi
Author | SHA1 | Date |
---|---|---|
Maxime | 4f1cc21aeb | |
Maxime | efaa4f9f0d | |
Maxime | 0cfa78e938 | |
Maxime | 5a89c8b24a | |
Maxime | de060b2ecf | |
Maxime | 13a34ad124 | |
Maxime | 127a3c44bf | |
Maxime | 66c2c31090 | |
Maxime | c03fcb31d6 | |
Maxime | 5593f8d563 | |
Maxime | 4232bca50d | |
Maxime | 0e3da8c8f6 | |
Maxime | fa6faa51c3 | |
Maxime | f4ce62543f | |
Maxime | d8771c67d8 | |
Maxime | 9f9ab9f1c0 | |
Maxime | cf792f2e7c | |
Maxime | 93a9d712c7 | |
Maxime | 883453f4a4 | |
Maxime | 982d07e8ad | |
Maxime | b0129aae79 | |
Maxime | ea400eefcd | |
Maxime | ebad682a65 | |
Maxime | 41d5f02879 | |
Maxime | cc27f9ef1d | |
Maxime | bfc39c22f7 | |
Maxime | dc08de2419 | |
mfrigo | a636b54a94 | |
mfrigo | 7c73c1d233 | |
mfrigo | 7a31b0ceb2 | |
mfrigo | 2274f8d6d0 | |
mfrigo | 4229c13b6b | |
mfrigo | 100ffbe05a | |
mfrigo | 0f50b5e678 | |
sbouaram | 0e00a839a3 | |
sbouaram | c354bece5f | |
sbouaram | 6299a6c7be | |
sbouaram | 718c39de00 | |
sbouaram | 9f66851529 | |
sbouaram | aa13d60ca6 | |
sbouaram | d169566cd1 | |
root | b54961b619 | |
root | c34d08ff70 | |
root | 46a72e1aef |
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/parcoursmob.iml" filepath="$PROJECT_DIR$/.idea/parcoursmob.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/themes" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -2,31 +2,37 @@ module git.coopgo.io/coopgo-apps/parcoursmob
|
|||
|
||||
go 1.18
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
||||
replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
||||
replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
||||
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/sbouaram/solidarity-service => ../../coopgo-platform/solidarity-service/
|
||||
|
||||
replace git.coopgo.io/coopgo-apps/silvermobi => ../../coopgo-apps/silvermobi/
|
||||
|
||||
replace git.coopgo.io/coopgo-platform/routing-service => ../../coopgo-platform/routing-service/
|
||||
|
||||
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
|
||||
|
||||
require (
|
||||
github.com/coreos/go-oidc v2.2.1+incompatible
|
||||
github.com/fogleman/gg v1.3.0
|
||||
github.com/go-playground/validator/v10 v10.11.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/go-playground/validator/v10 v10.12.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/mux v1.8.1
|
||||
github.com/gorilla/sessions v1.2.1
|
||||
github.com/paulmach/go.geojson v1.4.0
|
||||
github.com/spf13/viper v1.13.0
|
||||
github.com/spf13/viper v1.18.2
|
||||
gitlab.scity.coop/maas/navitia-golang v0.0.0-20220429110621-5c22d6efdd0c
|
||||
go.etcd.io/etcd/client/v3 v3.5.4
|
||||
go.etcd.io/etcd/client/v3 v3.5.10
|
||||
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
|
||||
golang.org/x/oauth2 v0.20.0
|
||||
google.golang.org/grpc v1.65.0
|
||||
google.golang.org/protobuf v1.34.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -34,80 +40,95 @@ require (
|
|||
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15
|
||||
git.coopgo.io/coopgo-platform/fleets v0.0.0-20230310144446-feb935f8bf4e
|
||||
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee0746c
|
||||
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20230329105908-a76c0412a386
|
||||
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20230430115320-f5bb2e7c2c26
|
||||
git.coopgo.io/coopgo-platform/routing-service v0.0.0-20230403183358-4d30329f06be
|
||||
git.coopgo.io/sbouaram/solidarity-service v0.0.0-00010101000000-000000000000
|
||||
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/rs/zerolog v1.32.0
|
||||
github.com/xuri/excelize/v2 v2.7.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash v1.1.0 // indirect
|
||||
ariga.io/atlas v0.13.1 // indirect
|
||||
github.com/agext/levenshtein v1.2.1 // indirect
|
||||
github.com/apparentlymart/go-textseg/v13 v13.0.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
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-openapi/inflect v0.19.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
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/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hashicorp/hcl/v2 v2.16.2 // 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/klauspost/compress v1.17.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||
github.com/leodido/go-urn v1.2.2 // indirect
|
||||
github.com/lib/pq v1.10.9 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // 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/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // 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/pelletier/go-toml v1.9.5 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/paulmach/orb v0.11.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.1 // 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/rs/xid v1.5.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.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/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.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/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/twpayne/go-geom v1.3.6 // indirect
|
||||
github.com/twpayne/go-polyline v1.1.1 // 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/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // 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
|
||||
go.mongodb.org/mongo-driver v1.10.1 // indirect
|
||||
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.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
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
|
||||
github.com/zclconf/go-cty v1.12.1 // indirect
|
||||
go.etcd.io/etcd/api/v3 v3.5.10 // indirect
|
||||
go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect
|
||||
go.mongodb.org/mongo-driver v1.15.0 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.21.0 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/mail.v2 v2.3.1 // indirect
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
|
||||
gopkg.in/square/go-jose.v2 v2.5.2-0.20210529014059-a5c7eec3c614 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,40 +12,58 @@ import (
|
|||
func (h APIHandler) GetCache(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
cacheid := vars["cacheid"]
|
||||
|
||||
d, err := h.cache.Get(cacheid)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
result := d
|
||||
|
||||
if data, ok := d.([]any); ok {
|
||||
if limitsmin, ok := r.URL.Query()["limits.min"]; ok {
|
||||
min, _ := strconv.Atoi(limitsmin[0])
|
||||
if limitsmax, ok := r.URL.Query()["limits.max"]; ok {
|
||||
max, _ := strconv.Atoi(limitsmax[0])
|
||||
if max > len(data) {
|
||||
result = data[min:]
|
||||
} else {
|
||||
result = data[min:max]
|
||||
}
|
||||
} else {
|
||||
result = data[min:]
|
||||
}
|
||||
// Use a channel to synchronize the goroutines
|
||||
ch := make(chan []byte)
|
||||
// Fetch data from cache asynchronously
|
||||
go func() {
|
||||
d, err := h.cache.Get(cacheid)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
ch <- nil
|
||||
return
|
||||
}
|
||||
var data []any
|
||||
if val, ok := d.([]any); ok {
|
||||
data = val
|
||||
} else {
|
||||
data = []any{d}
|
||||
}
|
||||
j := toJSON(data, w, r)
|
||||
ch <- j // Signal that the data has been fetched successfully
|
||||
close(ch)
|
||||
}()
|
||||
// wait for the JSON marshaling goroutine to finish
|
||||
j := <-ch
|
||||
if j == nil {
|
||||
return // Stop processing if an error occurred
|
||||
}
|
||||
|
||||
j, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Send the JSON response to the client
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(j)
|
||||
|
||||
<-ch
|
||||
}
|
||||
func toJSON(data []any, w http.ResponseWriter, r *http.Request) []byte {
|
||||
result := data
|
||||
if limitsmin, ok := r.URL.Query()["limits.min"]; ok {
|
||||
min, _ := strconv.Atoi(limitsmin[0])
|
||||
if limitsmax, ok := r.URL.Query()["limits.max"]; ok {
|
||||
max, _ := strconv.Atoi(limitsmax[0])
|
||||
if max > len(data) {
|
||||
result = data[min:]
|
||||
} else {
|
||||
result = data[min:max]
|
||||
}
|
||||
} else {
|
||||
result = data[min:]
|
||||
}
|
||||
}
|
||||
j, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return nil
|
||||
}
|
||||
return j
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
|
@ -27,79 +28,83 @@ import (
|
|||
)
|
||||
|
||||
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
accounts, err := h.services.GetAccounts()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
beneficiaries, err := h.services.GetBeneficiaries()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
bookings, err := h.services.GetBookings()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
request := &groupsmanagement.GetGroupsRequest{
|
||||
Namespaces: []string{"parcoursmob_organizations"},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
sort.Sort(sorting.GroupsByName(groups))
|
||||
////////////////////////////////////add event////////////////////////////////////////////
|
||||
rresp, 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 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()
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
accounts, beneficiaries []mobilityaccountsstorage.Account
|
||||
bookings []fleetsstorage.Booking
|
||||
accountsErr, beneficiariesErr, bookingsErr, groupsResponseErr, eventsResponseErr, groupsBatchErr error
|
||||
groups = []groupstorage.Group{}
|
||||
responses = []agendastorage.Event{}
|
||||
groupsResponse *groupsmanagement.GetGroupsResponse
|
||||
eventsResponse *agenda.GetEventsResponse
|
||||
groupids = []string{}
|
||||
groupsBatchResponse *groupsmanagement.GetGroupsBatchResponse
|
||||
)
|
||||
// Retrieve accounts in a goroutine
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
accounts, accountsErr = h.services.GetAccounts()
|
||||
}()
|
||||
// Retrieve beneficiaries in a goroutine
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
beneficiaries, beneficiariesErr = h.services.GetBeneficiaries()
|
||||
}()
|
||||
// Retrieve bookings in a goroutine
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
bookings, bookingsErr = h.services.GetBookings()
|
||||
}()
|
||||
// Retrieve groupsRequest in a goroutine
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
request := &groupsmanagement.GetGroupsRequest{
|
||||
Namespaces: []string{"parcoursmob_organizations"},
|
||||
}
|
||||
groupsResponse, groupsResponseErr = h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
||||
for _, group := range groupsResponse.Groups {
|
||||
g := group.ToStorageType()
|
||||
groups = append(groups, g)
|
||||
}
|
||||
sort.Sort(sorting.GroupsByName(groups))
|
||||
}()
|
||||
// Retrieve Events in a goroutine
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
eventsResponse, eventsResponseErr = h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
})
|
||||
for _, e := range eventsResponse.Events {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
responses = append(responses, e.ToStorageType())
|
||||
}
|
||||
sort.Sort(sorting.EventsByStartdate(responses))
|
||||
}()
|
||||
wg.Add(1)
|
||||
// Retrieve groupsBatch in a goroutine
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
groupsBatchResponse, groupsBatchErr = h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groupps := map[string]any{}
|
||||
if groupsBatchErr == nil {
|
||||
for _, g := range groupsBatchResponse.Groups {
|
||||
groupps[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
}()
|
||||
wg.Wait()
|
||||
if accountsErr != nil || beneficiariesErr != nil || bookingsErr != nil || groupsResponseErr != nil || eventsResponseErr != nil {
|
||||
fmt.Println(accountsErr, beneficiariesErr, bookingsErr, groupsResponseErr, eventsResponseErr, groupsBatchErr)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings, responses)
|
||||
}
|
||||
|
||||
|
@ -155,22 +160,23 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
|
|||
Namespace: "parcoursmob_roles",
|
||||
},
|
||||
}
|
||||
|
||||
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_organization)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}()
|
||||
// Create the admin role for the organization
|
||||
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_role)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
_, err = h.services.GRPC.GroupsManagement.AddGroup(context.TODO(), request_role)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}()
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
@ -205,165 +211,167 @@ func (h *ApplicationHandler) AdministrationGroupDisplay(w http.ResponseWriter, r
|
|||
func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
groupid := vars["groupid"]
|
||||
var (
|
||||
groupresp *groupsmanagement.GetGroupResponse
|
||||
accountresp *accounts.GetAccountUsernameResponse
|
||||
err error
|
||||
)
|
||||
go func() {
|
||||
groupresp, err = h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
||||
Id: groupid,
|
||||
Namespace: "parcoursmob_organizations",
|
||||
})
|
||||
|
||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
||||
Id: groupid,
|
||||
Namespace: "parcoursmob_organizations",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}()
|
||||
r.ParseForm()
|
||||
|
||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||
Username: r.FormValue("username"),
|
||||
Namespace: "parcoursmob",
|
||||
})
|
||||
go func() {
|
||||
accountresp, err = h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||
Username: r.FormValue("username"),
|
||||
Namespace: "parcoursmob",
|
||||
})
|
||||
if err == nil {
|
||||
// Account already exists : adding the existing account to admin list
|
||||
account := accountresp.Account.ToStorageType()
|
||||
account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid)
|
||||
account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid+":admin")
|
||||
|
||||
if err == nil {
|
||||
// Account already exists : adding the existing account to admin list
|
||||
account := accountresp.Account.ToStorageType()
|
||||
account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid)
|
||||
account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid+":admin")
|
||||
as, _ := accounts.AccountFromStorageType(&account)
|
||||
|
||||
as, _ := accounts.AccountFromStorageType(&account)
|
||||
_, err = h.services.GRPC.MobilityAccounts.UpdateData(
|
||||
context.TODO(),
|
||||
&accounts.UpdateDataRequest{
|
||||
Account: as,
|
||||
},
|
||||
)
|
||||
|
||||
_, err = h.services.GRPC.MobilityAccounts.UpdateData(
|
||||
context.TODO(),
|
||||
&accounts.UpdateDataRequest{
|
||||
Account: as,
|
||||
},
|
||||
)
|
||||
|
||||
fmt.Println(err)
|
||||
|
||||
data := map[string]any{
|
||||
"group": groupresp.Group.ToStorageType().Data["name"],
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("onboarding.existing_administrator", r.FormValue("username"), data); err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
data := map[string]any{
|
||||
"group": groupresp.Group.ToStorageType().Data["name"],
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("onboarding.existing_administrator", r.FormValue("username"), data); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
||||
return
|
||||
} else {
|
||||
// Onboard now administrator
|
||||
onboarding := map[string]any{
|
||||
"username": r.FormValue("username"),
|
||||
"group": groupid,
|
||||
"admin": true,
|
||||
}
|
||||
|
||||
b := make([]byte, 16)
|
||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
key := base64.RawURLEncoding.EncodeToString(b)
|
||||
|
||||
h.cache.PutWithTTL("onboarding/"+key, onboarding, 168*time.Hour) // 1 week TTL
|
||||
|
||||
data := map[string]any{
|
||||
"group": groupresp.Group.ToStorageType().Data["name"],
|
||||
"key": key,
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("onboarding.new_administrator", r.FormValue("username"), data); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
||||
return
|
||||
} else {
|
||||
// Onboard now administrator
|
||||
onboarding := map[string]any{
|
||||
"username": r.FormValue("username"),
|
||||
"group": groupid,
|
||||
"admin": true,
|
||||
}
|
||||
|
||||
b := make([]byte, 16)
|
||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
key := base64.RawURLEncoding.EncodeToString(b)
|
||||
|
||||
h.cache.PutWithTTL("onboarding/"+key, onboarding, 168*time.Hour) // 1 week TTL
|
||||
|
||||
data := map[string]any{
|
||||
"group": groupresp.Group.ToStorageType().Data["name"],
|
||||
"key": key,
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("onboarding.new_administrator", r.FormValue("username"), data); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
||||
return
|
||||
}()
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
groupid := vars["groupid"]
|
||||
var (
|
||||
group storage.Group
|
||||
)
|
||||
groupCh := make(chan storage.Group)
|
||||
go func() {
|
||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
||||
Id: groupid,
|
||||
Namespace: "parcoursmob_organizations",
|
||||
})
|
||||
|
||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
||||
Id: groupid,
|
||||
Namespace: "parcoursmob_organizations",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
group := groupresp.Group.ToStorageType()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
group := groupresp.Group.ToStorageType()
|
||||
groupCh <- group
|
||||
}()
|
||||
r.ParseForm()
|
||||
go func() {
|
||||
group = <-groupCh
|
||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||
Username: r.FormValue("username"),
|
||||
Namespace: "parcoursmob",
|
||||
})
|
||||
if err == nil {
|
||||
account := accountresp.Account.ToStorageType()
|
||||
account.Data["groups"] = append(account.Data["groups"].([]any), group.ID)
|
||||
|
||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||
Username: r.FormValue("username"),
|
||||
Namespace: "parcoursmob",
|
||||
})
|
||||
as, _ := accounts.AccountFromStorageType(&account)
|
||||
|
||||
if err == nil {
|
||||
account := accountresp.Account.ToStorageType()
|
||||
account.Data["groups"] = append(account.Data["groups"].([]any), group.ID)
|
||||
_, err = h.services.GRPC.MobilityAccounts.UpdateData(
|
||||
context.TODO(),
|
||||
&accounts.UpdateDataRequest{
|
||||
Account: as,
|
||||
},
|
||||
)
|
||||
data := map[string]any{
|
||||
"group": group.Data["name"],
|
||||
}
|
||||
|
||||
as, _ := accounts.AccountFromStorageType(&account)
|
||||
if err := h.emailing.Send("onboarding.existing_member", r.FormValue("username"), data); err != nil {
|
||||
}
|
||||
|
||||
_, err = h.services.GRPC.MobilityAccounts.UpdateData(
|
||||
context.TODO(),
|
||||
&accounts.UpdateDataRequest{
|
||||
Account: as,
|
||||
},
|
||||
)
|
||||
|
||||
fmt.Println(err)
|
||||
|
||||
data := map[string]any{
|
||||
"group": group.Data["name"],
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("onboarding.existing_member", r.FormValue("username"), data); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/app/group/settings", http.StatusFound)
|
||||
return
|
||||
} else {
|
||||
// Onboard now administrator
|
||||
onboarding := map[string]any{
|
||||
"username": r.FormValue("username"),
|
||||
"group": group.ID,
|
||||
"admin": false,
|
||||
}
|
||||
|
||||
b := make([]byte, 16)
|
||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
http.Redirect(w, r, "/app/group/settings", http.StatusFound)
|
||||
return
|
||||
} else {
|
||||
// Onboard now administrator
|
||||
onboarding := map[string]any{
|
||||
"username": r.FormValue("username"),
|
||||
"group": group.ID,
|
||||
"admin": false,
|
||||
}
|
||||
|
||||
b := make([]byte, 16)
|
||||
if _, err := io.ReadFull(rand.Reader, b); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
key := base64.RawURLEncoding.EncodeToString(b)
|
||||
|
||||
h.cache.PutWithTTL("onboarding/"+key, onboarding, 168*time.Hour) // 1 week TTL
|
||||
data := map[string]any{
|
||||
"group": group.Data["name"],
|
||||
"key": key,
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("onboarding.new_member", r.FormValue("username"), data); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
key := base64.RawURLEncoding.EncodeToString(b)
|
||||
|
||||
h.cache.PutWithTTL("onboarding/"+key, onboarding, 168*time.Hour) // 1 week TTL
|
||||
|
||||
data := map[string]any{
|
||||
"group": group.Data["name"],
|
||||
"key": key,
|
||||
}
|
||||
|
||||
if err := h.emailing.Send("onboarding.new_member", r.FormValue("username"), data); err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}()
|
||||
http.Redirect(w, r, "/app/administration/groups/"+group.ID, http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -20,13 +20,20 @@ import (
|
|||
profilepictures "git.coopgo.io/coopgo-apps/parcoursmob/utils/profile-pictures"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
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"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/mux"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
|
@ -41,6 +48,67 @@ type BeneficiariesForm struct {
|
|||
Gender string `json:"gender"`
|
||||
}
|
||||
|
||||
type Event_Beneficiary interface {
|
||||
Name() string
|
||||
Date() time.Time
|
||||
DateEnd() time.Time
|
||||
Type() string
|
||||
Db() string
|
||||
ID() string
|
||||
Icons() string
|
||||
Status() int
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
IDVal string
|
||||
NameVal string
|
||||
DateVal time.Time
|
||||
DateEndVal time.Time
|
||||
TypeVal string
|
||||
DbVal string
|
||||
Deleted bool
|
||||
IconSet string
|
||||
StatusVal int
|
||||
}
|
||||
|
||||
func (e Event) Name() string {
|
||||
return e.NameVal
|
||||
}
|
||||
|
||||
func (e Event) Date() time.Time {
|
||||
return e.DateVal
|
||||
}
|
||||
|
||||
func (e Event) DateEnd() time.Time {
|
||||
return e.DateEndVal
|
||||
}
|
||||
|
||||
func (e Event) Type() string {
|
||||
return e.TypeVal
|
||||
}
|
||||
|
||||
func (e Event) ID() string {
|
||||
return e.IDVal
|
||||
}
|
||||
|
||||
func (e Event) Db() string {
|
||||
return e.DbVal
|
||||
}
|
||||
|
||||
func (e Event) Icons() string {
|
||||
return e.IconSet
|
||||
}
|
||||
|
||||
func (e Event) Status() int {
|
||||
return e.StatusVal
|
||||
}
|
||||
|
||||
func sortByDate(events []Event_Beneficiary) {
|
||||
sort.Slice(events, func(i, j int) bool {
|
||||
return events[i].Date().After(events[j].Date())
|
||||
})
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
accounts, err := h.beneficiaries(r)
|
||||
|
@ -52,9 +120,17 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
|
|||
|
||||
sort.Sort(sorting.BeneficiariesByName(accounts))
|
||||
|
||||
accountssolidarity, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, accountssolidarity, 1*time.Hour)
|
||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||
h.Renderer.BeneficiariesList(w, r, accounts, cacheid)
|
||||
h.Renderer.BeneficiariesList(w, r, accounts,accountssolidarity, cacheid)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) BeneficiaryCreate(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -135,6 +211,35 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
|||
return
|
||||
}
|
||||
|
||||
subscriptionrequest := &agenda.GetSubscriptionByUserRequest{
|
||||
Subscriber: beneficiaryID,
|
||||
}
|
||||
|
||||
subcriptionresp, err := h.services.GRPC.Agenda.GetSubscriptionByUser(context.TODO(), subscriptionrequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
events := []agendastorage.Event{}
|
||||
currentTime := time.Now().Truncate(24 * time.Hour)
|
||||
|
||||
for _, e := range subcriptionresp.Subscription {
|
||||
eventresquest := &agenda.GetEventRequest{
|
||||
Id: e.Eventid,
|
||||
}
|
||||
eventresp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), eventresquest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
events = append(events, eventresp.Event.ToStorageType())
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(events))
|
||||
|
||||
bookingsrequest := &fleets.GetDriverBookingsRequest{
|
||||
Driver: beneficiaryID,
|
||||
}
|
||||
|
@ -145,12 +250,78 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
|||
return
|
||||
}
|
||||
|
||||
bookings := []any{}
|
||||
bookings := []fleetsstorage.Booking{}
|
||||
|
||||
for _, b := range bookingsresp.Bookings {
|
||||
bookings = append(bookings, b.ToStorageType())
|
||||
}
|
||||
|
||||
var events_list []Event_Beneficiary
|
||||
var status_event int
|
||||
|
||||
for _, e := range events {
|
||||
|
||||
if e.Startdate.After(currentTime) {
|
||||
status_event = 1
|
||||
} else if e.Startdate.Before(currentTime) && e.Enddate.After(currentTime) || e.Enddate.Equal(currentTime) {
|
||||
status_event = 2
|
||||
} else {
|
||||
status_event = 3
|
||||
}
|
||||
|
||||
event := Event{
|
||||
NameVal: e.Name,
|
||||
DateVal: e.Startdate,
|
||||
DateEndVal: e.Enddate,
|
||||
TypeVal: e.Type,
|
||||
IDVal: e.ID,
|
||||
DbVal: "/app/agenda/",
|
||||
IconSet: "calendar",
|
||||
StatusVal: status_event,
|
||||
}
|
||||
|
||||
events_list = append(events_list, event)
|
||||
}
|
||||
|
||||
var status_booking int
|
||||
for _, b := range bookings {
|
||||
|
||||
if b.Enddate.After(currentTime) || b.Enddate.Equal(currentTime) {
|
||||
GetVehiculeRequest := &fleets.GetVehicleRequest{
|
||||
Vehicleid: b.Vehicleid,
|
||||
}
|
||||
|
||||
GetVehiculeResp, err := h.services.GRPC.Fleets.GetVehicle(context.Background(), GetVehiculeRequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if b.Startdate.After(currentTime) {
|
||||
status_booking = 1
|
||||
} else if b.Startdate.Before(currentTime) && b.Enddate.After(currentTime) || b.Enddate.Equal(currentTime) {
|
||||
status_booking = 2
|
||||
} else {
|
||||
status_booking = 3
|
||||
}
|
||||
|
||||
event := Event{
|
||||
NameVal: GetVehiculeResp.Vehicle.ToStorageType().Data["name"].(string),
|
||||
DateVal: b.Startdate,
|
||||
DateEndVal: b.Enddate,
|
||||
TypeVal: "Réservation de véhicule",
|
||||
IDVal: b.ID,
|
||||
DbVal: "/app/vehicles-management/bookings/",
|
||||
IconSet: "vehicle",
|
||||
StatusVal: status_booking,
|
||||
}
|
||||
|
||||
events_list = append(events_list, event)
|
||||
}
|
||||
}
|
||||
sortByDate(events_list)
|
||||
|
||||
groupsrequest := &groupsmanagement.GetGroupsRequest{
|
||||
Namespaces: []string{"parcoursmob_organizations"},
|
||||
Member: beneficiaryID,
|
||||
|
@ -165,11 +336,56 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
|
|||
for _, o := range groupsresp.Groups {
|
||||
organizations = append(organizations, o.ToStorageType())
|
||||
}
|
||||
|
||||
|
||||
beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types")
|
||||
file_types_map := h.config.GetStringMapString("storage.files.file_types")
|
||||
|
||||
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents)
|
||||
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) BeneficiarySolidarityDisplay(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
vars := mux.Vars(r)
|
||||
beneficiaryID := vars["beneficiaryid"]
|
||||
|
||||
passenger := solidarity_service.GetPassengerRequest{
|
||||
Passenger: &solidarity_service.User{
|
||||
Id: beneficiaryID,
|
||||
},
|
||||
}
|
||||
|
||||
accountssolidarity, err := h.services.GRPC.SolidarityService.GetPassenger(context.TODO(), &passenger)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
solidarity_booking := &solidarity_service.GetBookingsByStatusRequest{
|
||||
Status : 0, /// 0 : pending
|
||||
UserId : beneficiaryID,
|
||||
Type: 1, /// 1 : passenger
|
||||
}
|
||||
|
||||
solidarity_bookings_list, err := h.services.GRPC.SolidarityService.GetBookingsByStatus(context.TODO(), solidarity_booking)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var bookings []any
|
||||
|
||||
for _, o := range solidarity_bookings_list.Booking {
|
||||
if(o.PickupDate != nil){
|
||||
bookings = append(bookings, o)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
h.Renderer.BeneficiarySolidarityDisplay(w, r , accountssolidarity , bookings)
|
||||
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -333,6 +549,8 @@ func filterAccount(r *http.Request, a *mobilityaccounts.Account) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// func BeneficiariesEventList()
|
||||
|
||||
func (h *ApplicationHandler) beneficiaries(r *http.Request) ([]mobilityaccountsstorage.Account, error) {
|
||||
var accounts = []mobilityaccountsstorage.Account{}
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
|
@ -373,7 +591,7 @@ func parseBeneficiariesForm(r *http.Request) (map[string]any, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
date = &d
|
||||
date = &d
|
||||
}
|
||||
|
||||
formData := BeneficiariesForm{
|
||||
|
|
|
@ -68,8 +68,10 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
|||
Mindate: timestamppb.Now(),
|
||||
})
|
||||
|
||||
for _, e := range eventsresp.Events {
|
||||
events = append(events, e.ToStorageType())
|
||||
if err == nil {
|
||||
for _, e := range eventsresp.Events {
|
||||
events = append(events, e.ToStorageType())
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(sorting.EventsByStartdate(events))
|
||||
|
|
|
@ -44,7 +44,7 @@ func (h *ApplicationHandler) Groups(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
resp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), request)
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
|
|
|
@ -27,7 +27,14 @@ var Arrive any
|
|||
|
||||
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
|
||||
var (
|
||||
journeys_results *navitia.JourneyResults
|
||||
carpool_results any
|
||||
vehicle_results []any
|
||||
)
|
||||
vehiclech := make(chan []any, 1)
|
||||
navitiaCh := make(chan *navitia.JourneyResults, 1)
|
||||
carpoolCh := make(chan any, 1)
|
||||
locTime, errTime := time.LoadLocation("Europe/Paris")
|
||||
if errTime != nil {
|
||||
fmt.Println("Loading timezone location Europe/Paris error : ")
|
||||
|
@ -70,91 +77,101 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
|
|||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
journeysRequest := func() {
|
||||
//TODO make it a library
|
||||
session, _ := navitia.NewCustom(
|
||||
h.config.GetString("services.navitia.api_key"),
|
||||
"https://api.navitia.io/v1",
|
||||
&http.Client{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
navitiaCh <- nil
|
||||
return
|
||||
}
|
||||
|
||||
request := navitia.JourneyRequest{
|
||||
From: types.ID(fmt.Sprintf("%f", departuregeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", departuregeo.Geometry.Point[1])),
|
||||
To: types.ID(fmt.Sprintf("%f", destinationgeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", destinationgeo.Geometry.Point[1])),
|
||||
Date: departuredatetime.Add(-2 * time.Hour),
|
||||
DateIsArrival: false, //TODO
|
||||
}
|
||||
|
||||
journeys, err = session.Journeys(context.Background(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusBadRequest)
|
||||
// return
|
||||
}
|
||||
navitiaCh <- journeys
|
||||
|
||||
//TODO make it a library
|
||||
session, _ := navitia.NewCustom(
|
||||
h.config.GetString("services.navitia.api_key"),
|
||||
"https://api.navitia.io/v1",
|
||||
&http.Client{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
request := navitia.JourneyRequest{
|
||||
From: types.ID(fmt.Sprintf("%f", departuregeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", departuregeo.Geometry.Point[1])),
|
||||
To: types.ID(fmt.Sprintf("%f", destinationgeo.Geometry.Point[0]) + ";" + fmt.Sprintf("%f", destinationgeo.Geometry.Point[1])),
|
||||
Date: departuredatetime.Add(-2 * time.Hour),
|
||||
DateIsArrival: false, //TODO
|
||||
}
|
||||
|
||||
journeys, err = session.Journeys(context.Background(), request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// w.WriteHeader(http.StatusBadRequest)
|
||||
// return
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CARPOOL
|
||||
// carpoolrequest := fmt.Sprintf(
|
||||
// "https://api.rdex.ridygo.fr/journeys.json?p[driver][state]=1&frequency=punctual&p[passenger][state]=0&p[from][latitude]=%f&p[from][longitude]=%f&p[to][latitude]=%f&p[to][longitude]=%f&p[outward][mindate]=%s&p[outward][maxdate]=%s",
|
||||
// departuregeo.Geometry.Point[1], departuregeo.Geometry.Point[0],
|
||||
// destinationgeo.Geometry.Point[1], destinationgeo.Geometry.Point[0],
|
||||
// departuredatetime.Format("2006-01-02"), departuredatetime.Add(24*time.Hour).Format("2006-01-02"))
|
||||
carpoolrequest := "https://api.rdex.ridygo.fr/journeys.json"
|
||||
carpoolRequest := func() {
|
||||
carpoolrequest := "https://api.rdex.ridygo.fr/journeys.json"
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", carpoolrequest, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
req.URL.RawQuery = fmt.Sprintf(
|
||||
"p[driver][state]=1&frequency=punctual&p[passenger][state]=0&p[from][latitude]=%f&p[from][longitude]=%f&p[to][latitude]=%f&p[to][longitude]=%f&p[outward][mindate]=%s&p[outward][maxdate]=%s",
|
||||
departuregeo.Geometry.Point[1], departuregeo.Geometry.Point[0],
|
||||
destinationgeo.Geometry.Point[1], destinationgeo.Geometry.Point[0],
|
||||
departuredatetime.Format("2006-01-02"), departuredatetime.Format("2006-01-02"))
|
||||
|
||||
req.Header.Set("X-API-KEY", "123456")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err == nil && resp.StatusCode == http.StatusOK {
|
||||
err = json.NewDecoder(resp.Body).Decode(&carpoolresults)
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", carpoolrequest, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if carpoolresults == nil {
|
||||
req.URL.RawQuery = fmt.Sprintf(
|
||||
"p[driver][state]=1&frequency=punctual&p[passenger][state]=0&p[from][latitude]=%f&p[from][longitude]=%f&p[to][latitude]=%f&p[to][longitude]=%f&p[outward][mindate]=%s&p[outward][maxdate]=%s",
|
||||
departuregeo.Geometry.Point[1], departuregeo.Geometry.Point[0],
|
||||
destinationgeo.Geometry.Point[1], destinationgeo.Geometry.Point[0],
|
||||
departuredatetime.Format("2006-01-02"), departuredatetime.Format("2006-01-02"))
|
||||
|
||||
req.Header.Set("X-API-KEY", "123456")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err == nil && resp.StatusCode == http.StatusOK {
|
||||
err = json.NewDecoder(resp.Body).Decode(&carpoolresults)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if carpoolresults == nil {
|
||||
carpoolresults = []any{}
|
||||
}
|
||||
} else {
|
||||
carpoolresults = []any{}
|
||||
}
|
||||
} else {
|
||||
carpoolresults = []any{}
|
||||
carpoolCh <- carpoolresults
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Vehicles
|
||||
|
||||
vehiclerequest := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
}
|
||||
vehicleresp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), vehiclerequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
for _, vehicle := range vehicleresp.Vehicles {
|
||||
v := vehicle.ToStorageType()
|
||||
if v.Free(departuredatetime.Add(-24*time.Hour), departuredatetime.Add(168*time.Hour)) {
|
||||
vehicles = append(vehicles, v)
|
||||
vehicleRequest := func() {
|
||||
vehiclerequest := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
}
|
||||
vehicleresp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), vehiclerequest)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
for _, vehicle := range vehicleresp.Vehicles {
|
||||
v := vehicle.ToStorageType()
|
||||
if v.Free(departuredatetime.Add(-24*time.Hour), departuredatetime.Add(168*time.Hour)) {
|
||||
vehicles = append(vehicles, v)
|
||||
}
|
||||
}
|
||||
vehiclech <- vehicles
|
||||
}
|
||||
go journeysRequest()
|
||||
go carpoolRequest()
|
||||
go vehicleRequest()
|
||||
carpool_results = <-carpoolCh
|
||||
journeys_results = <-navitiaCh
|
||||
vehicle_results = <-vehiclech
|
||||
}
|
||||
|
||||
h.Renderer.JourneysSearch(w, r, carpoolresults, journeys, vehicles, searched, departuregeo, destinationgeo, departuredate, departuretime)
|
||||
h.Renderer.JourneysSearch(w, r, carpool_results, journeys_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime)
|
||||
}
|
||||
|
||||
type GroupsModule []groupstorage.Group
|
||||
|
|
|
@ -0,0 +1,150 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
"github.com/google/uuid"
|
||||
geojson "github.com/paulmach/go.geojson"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
var BookingData Booking
|
||||
|
||||
type Booking struct {
|
||||
bookingData solidarity_service.CreateBookingSolidarityRequest
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
parcourmobAccounts, err := h.beneficiaries(r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||
h.cache.PutWithTTL(cacheid, parcourmobAccounts, 1*time.Hour)
|
||||
|
||||
|
||||
if r.Method == "GET" && r.FormValue("date") != ""{
|
||||
|
||||
DepartureAddress := r.FormValue("departure");
|
||||
DestinationAddress := r.FormValue("destination");
|
||||
PickupDate := r.FormValue("date");
|
||||
PassengerId := r.FormValue("passenger_id")
|
||||
|
||||
layout := "2006-01-02T15:04"
|
||||
|
||||
dateParsed, err := time.Parse(layout, PickupDate)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
departuregeo *geojson.Feature
|
||||
destinationgeo *geojson.Feature
|
||||
)
|
||||
|
||||
timestamp := timestamppb.New(dateParsed)
|
||||
|
||||
if PickupDate != "" && DepartureAddress != "" && DestinationAddress != "" {
|
||||
// searched = true
|
||||
|
||||
var err error
|
||||
|
||||
departuregeo, err = geojson.UnmarshalFeature([]byte(DepartureAddress))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
destinationgeo, err = geojson.UnmarshalFeature([]byte(DestinationAddress))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
request := solidarity_service.DriverJourneysRequest{
|
||||
DepartureDate: timestamp,
|
||||
Departure: &solidarity_service.Feature{
|
||||
Lat: departuregeo.Geometry.Point[0],
|
||||
Long: departuregeo.Geometry.Point[1],
|
||||
Address: DepartureAddress,
|
||||
},
|
||||
}
|
||||
|
||||
drivers, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), &request)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
BookingData.bookingData = solidarity_service.CreateBookingSolidarityRequest {
|
||||
Booking : &solidarity_service.BookingSolidarityRequest {
|
||||
|
||||
PassengerId: PassengerId,
|
||||
DepartureAddress: &solidarity_service.Feature{
|
||||
Lat: departuregeo.Geometry.Point[0],
|
||||
Long: departuregeo.Geometry.Point[1],
|
||||
Address: DepartureAddress,
|
||||
},
|
||||
DestinationAddress: &solidarity_service.Feature{
|
||||
Lat: destinationgeo.Geometry.Point[0],
|
||||
Long: destinationgeo.Geometry.Point[1],
|
||||
Address: DepartureAddress,
|
||||
},
|
||||
PickupDate : timestamp,
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println(BookingData.bookingData, "booking")
|
||||
|
||||
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData, accounts, parcourmobAccounts, cacheid)
|
||||
|
||||
} else if r.Method == "POST" {
|
||||
|
||||
driverId := r.FormValue("driver_id")
|
||||
id := uuid.New().String()
|
||||
|
||||
|
||||
BookingData.bookingData.Booking.DriverId = driverId
|
||||
BookingData.bookingData.Booking.Id = id
|
||||
|
||||
booking, err := h.services.GRPC.SolidarityService.CreateBookingSolidarity(context.TODO(), &BookingData.bookingData)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
h.Renderer.SolidarityServiceBooking(w, r, booking, parcourmobAccounts)
|
||||
|
||||
}else {
|
||||
|
||||
h.Renderer.SolidarityService(w, r, accounts, parcourmobAccounts, cacheid)
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
|
||||
fmt.Println("invoked")
|
||||
var beneficiary mobilityaccountsstorage.Account
|
||||
|
||||
beneficiarydocuments := []filestorage.FileInfo{}
|
||||
|
@ -349,6 +349,9 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.
|
|||
vehicles, _ := h.services.GetVehiclesMap()
|
||||
groups, _ := h.services.GetGroupsMap()
|
||||
|
||||
// fmt.Println("bookings : ", bookings)
|
||||
// fmt.Println("vehicles : ", vehicles)
|
||||
// fmt.Println("groups : ", groups)
|
||||
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,27 +19,26 @@ import (
|
|||
|
||||
func main() {
|
||||
cfg, err := ReadConfig()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var (
|
||||
address = cfg.GetString("server.listen")
|
||||
//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)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(cfg)
|
||||
kv, err := cache.NewKVHandler(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
filestorage, err := cache.NewFileStorage(cfg)
|
||||
|
||||
idp, err := identification.NewIdentificationProvider(cfg, svc, kv)
|
||||
|
@ -138,6 +137,11 @@ func main() {
|
|||
application.HandleFunc("/support/", applicationHandler.SupportSend)
|
||||
/*********************** CODE GROUP **************************/
|
||||
|
||||
//=================================silvermobi====================================
|
||||
application.HandleFunc("/solidarity_service/", applicationHandler.DriversJourney)
|
||||
application.HandleFunc("/beneficiaries/solidarity_service/{beneficiaryid}", applicationHandler.BeneficiarySolidarityDisplay)
|
||||
|
||||
|
||||
appGroup := application.PathPrefix("/group_module").Subrouter()
|
||||
appGroup.HandleFunc("/", applicationHandler.Groups)
|
||||
appGroup.HandleFunc("/groups", applicationHandler.CreateGroupModule)
|
||||
|
@ -172,11 +176,9 @@ func main() {
|
|||
export.Use(idp.Middleware)
|
||||
export.Use(idp.GroupsMiddleware)
|
||||
|
||||
fmt.Println("-> HTTP server listening on", address)
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: r,
|
||||
Addr: address,
|
||||
Addr: "0.0.0.0:9000",
|
||||
WriteTimeout: 15 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
}
|
||||
|
|
|
@ -2,10 +2,13 @@ package renderer
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
)
|
||||
|
||||
const beneficiariesMenu = "beneficiaries"
|
||||
|
@ -14,6 +17,16 @@ type BeneficiariesListState struct {
|
|||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
||||
}
|
||||
|
||||
type BeneficiarySolidarityState struct {
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||
BeneficiarySolidarity *solidarity_service.GetPassengerResponse `json:"beneficiarysolidarity"`
|
||||
BookingSolidarity *solidarity_service.GetBookingsByStatusResponse `json:"bookingsolidarity"`
|
||||
|
||||
}
|
||||
|
||||
func (s BeneficiariesListState) JSON() template.JS {
|
||||
|
@ -22,20 +35,33 @@ func (s BeneficiariesListState) JSON() template.JS {
|
|||
}
|
||||
|
||||
func (s BeneficiariesListState) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < len(s.Beneficiaries) {
|
||||
if b < len(s.Beneficiaries) {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) BeneficiariesList(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||
func (s BeneficiarySolidarityState) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s BeneficiarySolidarityState) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < 5 {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) BeneficiariesList(w http.ResponseWriter, r *http.Request, accounts []mobilityaccountsstorage.Account, accountssolidarity *solidarity_service.GetAllPassengersResponse, cacheid string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.list.files")
|
||||
|
||||
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
||||
state.ViewState = BeneficiariesListState{
|
||||
Count: len(accounts),
|
||||
Count: len(accounts),
|
||||
CacheId: cacheid,
|
||||
Beneficiaries: accounts,
|
||||
BeneficiariesSolidarity : accountssolidarity,
|
||||
}
|
||||
|
||||
renderer.Render("beneficiaries_list", w, r, files, state)
|
||||
|
@ -52,7 +78,7 @@ type BeneficiariesDisplayState struct {
|
|||
Beneficiary any
|
||||
}
|
||||
|
||||
func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []any, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any) {
|
||||
func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []fleetsstorage.Booking, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any, event interface{}) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
|
||||
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
||||
state.ViewState = map[string]any{
|
||||
|
@ -62,8 +88,19 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ
|
|||
"file_types_map": file_types_map,
|
||||
"documents": documents,
|
||||
"organizations": organizations,
|
||||
"event": event,
|
||||
}
|
||||
renderer.Render("beneficiaries_display", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) BeneficiarySolidarityDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, solidarity_bookings_list []any ) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
|
||||
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
|
||||
state.ViewState = map[string]any{
|
||||
"beneficiary": beneficiary,
|
||||
"bookingSolidarity" : solidarity_bookings_list,
|
||||
}
|
||||
fmt.Println(solidarity_bookings_list)
|
||||
renderer.Render("beneficiaries_display", w, r, files, state)
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,20 @@ func TimeFrom(d any) *time.Time {
|
|||
return nil
|
||||
}
|
||||
|
||||
func TimestampFrom(d any) *time.Time {
|
||||
|
||||
if date, ok := d.(time.Time); ok {
|
||||
return &date
|
||||
} else if date, ok := d.(string); ok {
|
||||
datetime, err := time.Parse("2006-01-02T15:04:05Z", date)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &datetime
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TimeFormat(d any, f string) string {
|
||||
date := TimeFrom(d)
|
||||
if date == nil {
|
||||
|
|
|
@ -251,6 +251,14 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
|
|||
Icon: "hero:outline/user-group",
|
||||
})
|
||||
}
|
||||
if modules["solidarity_service"] != nil && modules["solidarity_service"].(bool) {
|
||||
ls.MenuItems = append(ls.MenuItems, MenuItem{
|
||||
Title: "Mobilité solidaire",
|
||||
Link: "/app/solidarity_service/",
|
||||
Active: menuState == solidarityserviceMenu,
|
||||
Icon: "hero:outline/map",
|
||||
})
|
||||
}
|
||||
return RenderState{
|
||||
IconSet: icons.NewIconSet(iconset),
|
||||
Group: group,
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package renderer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
)
|
||||
|
||||
const solidarityserviceMenu = "solidarity_service"
|
||||
|
||||
|
||||
type SolidarityListState struct {
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
||||
Drivers *solidarity_service.DriverJourneysResponse `json:"drivers"`
|
||||
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||
|
||||
}
|
||||
|
||||
type BeneficiariesSolidarityListState struct {
|
||||
Count int `json:"count"`
|
||||
CacheId string `json:"cache_id"`
|
||||
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
|
||||
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||
|
||||
}
|
||||
|
||||
type SolidarityBookingsState struct {
|
||||
Bookings *solidarity_service.CreateBookingSolidarityResponse `json:"bookings"`
|
||||
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
|
||||
|
||||
}
|
||||
|
||||
func (s BeneficiariesSolidarityListState) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s BeneficiariesSolidarityListState) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < 5 {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (s SolidarityListState) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s SolidarityListState) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < 5 {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (s SolidarityBookingsState) JSON() template.JS {
|
||||
result, _ := json.Marshal(s)
|
||||
return template.JS(result)
|
||||
}
|
||||
|
||||
func (s SolidarityBookingsState) JSONWithLimits(a int, b int) template.JS {
|
||||
if b < 5 {
|
||||
s.Beneficiaries = s.Beneficiaries[a:b]
|
||||
}
|
||||
return s.JSON()
|
||||
}
|
||||
|
||||
func (renderer *Renderer) SolidarityService(w http.ResponseWriter, r *http.Request, accounts *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||
state.ViewState = BeneficiariesSolidarityListState{
|
||||
Count: len(parcourmobAccounts),
|
||||
CacheId: cacheid,
|
||||
BeneficiariesSolidarity: accounts,
|
||||
Beneficiaries: parcourmobAccounts,
|
||||
}
|
||||
|
||||
renderer.Render("solidarity_service", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse, parcourmobAccounts []mobilityaccountsstorage.Account) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||
state.ViewState = SolidarityBookingsState{
|
||||
Bookings: bookings,
|
||||
Beneficiaries: parcourmobAccounts,
|
||||
|
||||
}
|
||||
|
||||
renderer.Render("solidarity_service", w, r, files, state)
|
||||
}
|
||||
|
||||
func (renderer *Renderer) SolidarityServiceListAvailableDrivers(w http.ResponseWriter, r *http.Request, drivers *solidarity_service.DriverJourneysResponse, booking *solidarity_service.CreateBookingSolidarityRequest, accounts *solidarity_service.GetAllPassengersResponse, parcourmobAccounts []mobilityaccountsstorage.Account, cacheid string) {
|
||||
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
|
||||
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
|
||||
state.ViewState = SolidarityListState {
|
||||
Count: len(parcourmobAccounts),
|
||||
BeneficiariesSolidarity: accounts,
|
||||
CacheId: cacheid,
|
||||
Drivers: drivers,
|
||||
Beneficiaries: parcourmobAccounts,
|
||||
|
||||
}
|
||||
|
||||
renderer.Render("solidarity_service", w, r, files, state)
|
||||
}
|
|
@ -2,6 +2,7 @@ package services
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
|
@ -56,13 +57,17 @@ func (s *ServicesHandler) GetBookings() (bookings []storage.Booking, err error)
|
|||
func (s *ServicesHandler) GetVehiclesMap() (vehicles map[string]storage.Vehicle, err error) {
|
||||
vehicles = map[string]storage.Vehicle{}
|
||||
|
||||
request := &fleets.GetVehiclesRequest{}
|
||||
request := &fleets.GetVehiclesRequest{
|
||||
Namespaces: []string{"parcoursmob"},
|
||||
}
|
||||
resp, err := s.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
for _, vehicle := range resp.Vehicles {
|
||||
vehicles[vehicle.Id] = vehicle.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
return vehicles, err
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@ import (
|
|||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
routing "git.coopgo.io/coopgo-platform/routing-service"
|
||||
solidarityservice "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type ServicesHandler struct {
|
||||
|
@ -13,10 +16,12 @@ type ServicesHandler struct {
|
|||
}
|
||||
|
||||
type GRPCServices struct {
|
||||
MobilityAccounts mobilityaccounts.MobilityAccountsClient
|
||||
GroupsManagement groupsmanagement.GroupsManagementClient
|
||||
Fleets fleets.FleetsClient
|
||||
Agenda agenda.AgendaClient
|
||||
MobilityAccounts mobilityaccounts.MobilityAccountsClient
|
||||
GroupsManagement groupsmanagement.GroupsManagementClient
|
||||
Fleets fleets.FleetsClient
|
||||
Agenda agenda.AgendaClient
|
||||
SolidarityService solidarityservice.SolidarityServiceClient
|
||||
Routing routing.RoutingService
|
||||
}
|
||||
|
||||
func NewServicesHandler(cfg *viper.Viper) (*ServicesHandler, error) {
|
||||
|
@ -25,6 +30,9 @@ func NewServicesHandler(cfg *viper.Viper) (*ServicesHandler, error) {
|
|||
groupsManagementDial = cfg.GetString("services.grpc.groupsmanagement.dial")
|
||||
fleetsDial = cfg.GetString("services.grpc.fleets.dial")
|
||||
agendaDial = cfg.GetString("services.grpc.agenda.dial")
|
||||
solidarityDial = cfg.GetString("services.grpc.solidarityservice.dial")
|
||||
routing_service_type = cfg.GetString("routing.type")
|
||||
valhalla_base_url = cfg.GetString("routing.valhalla.base_url")
|
||||
)
|
||||
mobilityAccounts, err := NewMobilityAccountService(mobilityAccountsDial)
|
||||
if err != nil {
|
||||
|
@ -46,12 +54,25 @@ func NewServicesHandler(cfg *viper.Viper) (*ServicesHandler, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
solidarityService, err := NewSolidarityService(solidarityDial)
|
||||
if err != nil {
|
||||
return nil , err
|
||||
}
|
||||
|
||||
routing, err := routing.NewRoutingService(routing_service_type, valhalla_base_url)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Could not initiate the routing service")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ServicesHandler{
|
||||
GRPC: GRPCServices{
|
||||
MobilityAccounts: mobilityAccounts,
|
||||
GroupsManagement: groupsManagement,
|
||||
Fleets: fleetsSvc,
|
||||
Agenda: agendaSvc,
|
||||
SolidarityService: solidarityService,
|
||||
Routing: routing,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
solidarityservice "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type SolidarityService struct {
|
||||
solidarityservice.SolidarityServiceClient
|
||||
}
|
||||
|
||||
func NewSolidarityService(silvermobiDial string) (*SolidarityService, error) {
|
||||
conn, err := grpc.Dial(silvermobiDial, grpc.WithInsecure())
|
||||
|
||||
client := solidarityservice.NewSolidarityServiceClient(conn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SolidarityService{
|
||||
SolidarityServiceClient: client,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Subproject commit db4c22699eff6756851b0d3eff430b7bbe4c1c1b
|
|
@ -0,0 +1 @@
|
|||
package storage
|
|
@ -74,6 +74,7 @@ func NewEtcdHandler(cfg *viper.Viper) (*EtcdHandler, error) {
|
|||
Password: password,
|
||||
DialTimeout: 5 * time.Second,
|
||||
})
|
||||
fmt.Println(endpoints,prefix,username,password)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
|
|
|
@ -15,4 +15,6 @@ type KVHandler interface {
|
|||
|
||||
func NewKVHandler(cfg *viper.Viper) (KVHandler, error) {
|
||||
return NewEtcdHandler(cfg)
|
||||
return nil, nil
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue