60 Commits

Author SHA1 Message Date
a04e53b47f add routes in main 2025-02-05 09:25:21 +01:00
726584b0fb front driver availabilities 2024-12-18 15:05:58 +01:00
50e939c455 list all bookings 2024-12-16 10:12:40 +01:00
3ad5711ae7 set driver availabilities 2024-12-12 12:27:22 +01:00
7a648ccd1b create driver 2024-12-11 15:26:18 +01:00
a8ef3b758f add createDriver renderer et handler 2024-12-04 17:46:25 +01:00
f43d02c762 getAllDrivers 2024-11-29 11:43:47 +01:00
163ffefbfb add onglet beneficiaries_silvermobi 2024-11-28 11:57:36 +01:00
8f21248c29 Add Trajets Solidaire in Deplacement 2024-11-22 17:26:32 +01:00
e811ea7a07 Les SilvermobiBeneficiaries deviennent des ParcourmobBEneficiaries 2024-11-07 18:14:48 +01:00
4f1cc21aeb fix 2024-10-04 18:57:37 +02:00
efaa4f9f0d up list silvermobiBookings 2024-09-26 17:42:18 +02:00
0cfa78e938 list silvermobiBooking by silvermobiUsers 2024-09-26 13:34:08 +02:00
5a89c8b24a create booking done 2024-09-25 15:16:02 +02:00
de060b2ecf front module mobilité solidaire 2024-09-19 11:14:02 +02:00
13a34ad124 Create booking done 2024-09-18 15:56:13 +02:00
127a3c44bf createBooking 2024-09-17 14:42:27 +02:00
66c2c31090 list drivers first_name + last_name 2024-09-17 10:30:29 +02:00
c03fcb31d6 list beneficiaries
+ select beneficiary
2024-09-12 10:52:47 +02:00
5593f8d563 fix form and request 2024-08-28 14:10:03 +02:00
4232bca50d add routing-service to parcourmob 2024-08-08 13:22:09 +02:00
0e3da8c8f6 fix connection 2024-08-07 15:01:01 +02:00
fa6faa51c3 changement d'ortographe 2024-08-07 11:47:35 +02:00
f4ce62543f connection grpc generique done 2024-08-02 15:02:35 +02:00
d8771c67d8 grpc done 2024-07-31 18:33:25 +02:00
9f9ab9f1c0 fix dialogue parcourmob <=> silvermobi 2024-07-31 14:04:53 +02:00
cf792f2e7c fix grpc call 2024-07-31 13:33:38 +02:00
93a9d712c7 add input in front + add connection via grpc to solidarity-service(vue) 2024-06-07 11:51:01 +02:00
883453f4a4 changement de variables 2024-05-02 09:54:51 +02:00
982d07e8ad change function's name in solidarity_mobility folders 2024-04-25 15:16:06 +02:00
b0129aae79 add silvermobi/storage 'dependencie' to solidarity_mobility handler 2024-04-25 15:12:49 +02:00
ea400eefcd change varsilvermobi to solidarity_mobility 2024-04-25 14:45:03 +02:00
ebad682a65 route for silvermobi frontend and backend 2024-04-24 16:05:21 +02:00
41d5f02879 fix mistakes 2024-04-24 12:49:03 +02:00
cc27f9ef1d add path to silvemobi.html in parcourmob/config.yaml + add path and state in renderer/silvermobi.go 2024-04-24 12:18:05 +02:00
bfc39c22f7 add route 'app/silvermobi' + add CRUD functions in handler's folder 2024-04-24 10:22:23 +02:00
dc08de2419 add module silvermobi to lateral navbar 2024-04-19 15:54:38 +02:00
a636b54a94 [+] Correction for véhicule partages 2023-12-08 13:29:25 +01:00
7c73c1d233 Merge branch 'dev' of https://git.coopgo.io/coopgo-apps/parcoursmob into dev 2023-11-24 17:06:12 +01:00
7a31b0ceb2 [+] merge main.go 2023-11-24 17:04:10 +01:00
2274f8d6d0 [+] bug fix regarding booking-list 2023-11-24 16:27:34 +01:00
4229c13b6b Implemented functional "Actions réalisées"
- Added events and vehicles inside it
- Included dates, characteristics, and names of events/vehicles
- Introduced color-coded badges to indicate the status of events/vehicles (ongoing or not)
2023-10-23 09:45:57 +02:00
100ffbe05a delete themes.zip 2023-09-06 13:32:49 +02:00
0f50b5e678 [+] adding in beneficiary-events the agenda-widget 2023-09-06 13:28:02 +02:00
275c8b1999 comments replace in go.mod 2023-08-07 10:52:29 +02:00
18e890ceed add filter in export fleets 2023-06-02 14:43:56 +02:00
b717be9b99 add filter in export fleets 2023-06-02 14:42:55 +02:00
ddb08cf671 add export agenda by Salim 2023-06-01 14:11:03 +02:00
4fe479c1fb edit exports/fleets 2023-06-01 10:59:21 +02:00
b0dd81bf67 Merge branch 'main' into dev 2023-05-31 11:19:04 +02:00
soukainna
3bfd2e1bfe fix err merge 2023-05-19 10:50:15 +02:00
soukainna
b5154bf9be Merge branch 'modifyVehicle' into dev 2023-05-19 10:45:34 +02:00
soukainna
96823f3289 update vehicle 2023-05-19 10:19:30 +02:00
soukainna
93cab33fb9 update vehicle 2023-05-19 10:19:06 +02:00
soukainna
d5bc764ef3 fix err 2023-05-12 13:00:19 +02:00
soukainna
1aeb6d50ef add logic fuction to update vehicles 2023-05-12 12:59:16 +02:00
f26d792b8b edit vehicles-management handler 2023-05-12 11:05:42 +02:00
bfd14d7f4c edit handlers vehicle-management for unbooking a vehicle 2023-05-10 09:52:57 +02:00
31e5eadc73 edit handlers and renderer for delete a booking vehicle 2023-05-05 15:14:56 +02:00
8f20a12bc5 edit config.yaml to add delete_booking route 2023-05-03 14:29:43 +02:00
29 changed files with 1443 additions and 786 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -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

8
.idea/modules.xml generated Normal file
View File

@@ -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>

9
.idea/parcoursmob.iml generated Normal file
View File

@@ -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>

7
.idea/vcs.xml generated Normal file
View File

@@ -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>

125
go.mod
View File

@@ -1,32 +1,40 @@
module git.coopgo.io/coopgo-apps/parcoursmob
go 1.18
go 1.22
// replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
toolchain go1.23.2
// replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
replace git.coopgo.io/coopgo-platform/mobility-accounts => ../../coopgo-platform/mobility-accounts/
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
replace git.coopgo.io/coopgo-platform/groups-management => ../../coopgo-platform/groups-management/
// replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
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.23.0
google.golang.org/grpc v1.68.1
google.golang.org/protobuf v1.34.2
)
require (
@@ -34,80 +42,93 @@ 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.33.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.7 // 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/paulmach/orb v0.11.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // 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.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // 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
)

761
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -20,11 +20,17 @@ 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/structpb"
@@ -41,6 +47,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)
@@ -135,6 +202,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 +241,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,
@@ -169,7 +331,84 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
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)
if r.Method == "POST" {
request := &mobilityaccounts.GetAccountRequest{
Id: beneficiaryID,
}
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
fields := resp.Account.Data.Fields
firstName, ok := fields["first_name"]
if !ok {
fmt.Println("first_name not found in the data")
w.WriteHeader(http.StatusInternalServerError)
return
}
lastName, ok := fields["last_name"]
if !ok {
fmt.Println("last_name not found in the data")
w.WriteHeader(http.StatusInternalServerError)
return
}
passenger := solidarity_service.PassengerTripRequest {
Passenger : &solidarity_service.User {
Id: resp.Account.Id,
FirstName: firstName.Kind.(*structpb.Value_StringValue).StringValue,
LastName: lastName.Kind.(*structpb.Value_StringValue).StringValue,
Alias: " ",
Grade: 0,
Picture: " ",
Gender: " ",
VerifiedIdentity: true,
},
}
silvermobiPassenger, err := h.services.GRPC.SolidarityService.SetPassengerTrip(context.TODO(), &passenger)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
t := silvermobiPassenger
t = t
}
solidarity_booking := &solidarity_service.GetBookingsByStatusRequest{
Status : 0, /// 0 : pending
UserId : beneficiaryID,
Type: 1, /// 1 : passenger
}
solidarity_bookings_object, err := h.services.GRPC.SolidarityService.GetBookingsByStatus(context.TODO(), solidarity_booking)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
var solidarity_bookings_list []any
for _, o := range solidarity_bookings_object.Booking {
if(o.PassengerPickupDate != nil){
solidarity_bookings_list = append(solidarity_bookings_list, o)
}
}
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents, events_list, solidarity_bookings_list)
}
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {
@@ -333,6 +572,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)

View File

@@ -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))

View File

@@ -14,27 +14,40 @@ import (
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"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
models "git.coopgo.io/coopgo-apps/parcoursmob/utils/models"
"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"
//"gitlab.scity.coop/maas/navitia-golang"
//"gitlab.scity.coop/maas/navitia-golang/types"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
var Depart any
var Arrive any
var SolidarityData models.SolidarityTransport
func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
var (
journeys_results *navitia.JourneyResults
//journeys_results *navitia.JourneyResults
carpool_results any
vehicle_results []any
solidarity_results models.SolidarityTransport
)
vehiclech := make(chan []any, 1)
navitiaCh := make(chan *navitia.JourneyResults, 1)
//navitiaCh := make(chan *navitia.JourneyResults, 1)
carpoolCh := make(chan any, 1)
solidarityCh := make(chan models.SolidarityTransport, 1)
locTime, errTime := time.LoadLocation("Europe/Paris")
if errTime != nil {
fmt.Println("Loading timezone location Europe/Paris error : ")
@@ -54,9 +67,11 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
var (
departuregeo *geojson.Feature
destinationgeo *geojson.Feature
journeys *navitia.JourneyResults
//journeys *navitia.JourneyResults
carpoolresults any
vehicles = []any{}
drivers []any
accounts []any
)
if departuredate != "" && departuretime != "" && departure != "" && destination != "" {
@@ -78,35 +93,35 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
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
}
// 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
}
// 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
// journeys, err = session.Journeys(context.Background(), request)
// if err != nil {
// fmt.Println(err)
// // w.WriteHeader(http.StatusBadRequest)
// // return
// }
// navitiaCh <- journeys
}
// }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CARPOOL
carpoolRequest := func() {
@@ -163,15 +178,117 @@ func (h *ApplicationHandler) JourneysSearch(w http.ResponseWriter, r *http.Reque
}
vehiclech <- vehicles
}
go journeysRequest()
///////////////////////////////////////////////////////////////////////////////////////////////////:::
//solidarity-service
solidarityRequest := func() {
timestamp := timestamppb.New(departuredatetime)
PassengerId := r.FormValue("passenger_id")
driverId := r.FormValue("driver_id")
id := uuid.New().String()
type Booking struct {
bookingData solidarity_service.CreateBookingSolidarityRequest
}
var BookingData Booking
accountsRequest, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{})
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
}
for _, o := range accountsRequest.Passenger {
accounts = append(accounts, o)
}
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
request := solidarity_service.DriverJourneysRequest{
DepartureDate: timestamp,
Departure: &solidarity_service.Feature{
Lat: departuregeo.Geometry.Point[0],
Long: departuregeo.Geometry.Point[1],
Address: departure,
},
}
driversRequest, err := h.services.GRPC.SolidarityService.DriverJourneys(context.TODO(), &request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
for _, o := range driversRequest.DriverJourneys {
drivers = append(drivers, o)
}
if r.Method == "POST" {
BookingData.bookingData = solidarity_service.CreateBookingSolidarityRequest {
Booking : &solidarity_service.BookingSolidarityRequest {
Id: id,
DriverId: driverId,
PassengerId: PassengerId,
DepartureAddress: &solidarity_service.Feature{
Lat: departuregeo.Geometry.Point[0],
Long: departuregeo.Geometry.Point[1],
Address: departure,
},
DestinationAddress: &solidarity_service.Feature{
Lat: destinationgeo.Geometry.Point[0],
Long: destinationgeo.Geometry.Point[1],
Address: departure,
},
PickupDate : timestamp,
},
}
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
}
booking = booking
SolidarityData = models.SolidarityTransport{
Drivers: drivers,
Beneficiaries: accounts,
}
}
SolidarityData = models.SolidarityTransport{
Drivers: drivers,
Beneficiaries: accounts,
}
solidarityCh <- SolidarityData
}
//go journeysRequest()
go carpoolRequest()
go vehicleRequest()
go solidarityRequest()
carpool_results = <-carpoolCh
journeys_results = <-navitiaCh
//journeys_results = <-navitiaCh
vehicle_results = <-vehiclech
solidarity_results = <-solidarityCh
}
h.Renderer.JourneysSearch(w, r, carpool_results, journeys_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime)
h.Renderer.JourneysSearch(w, r, carpool_results, vehicle_results, searched, departuregeo, destinationgeo, departuredate, departuretime, solidarity_results) //journeys_results,
}
type GroupsModule []groupstorage.Group

View File

@@ -0,0 +1,260 @@
package application
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strconv"
"time"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
"github.com/google/uuid"
"github.com/gorilla/mux"
geojson "github.com/paulmach/go.geojson"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
var BookingData Booking
type Booking struct {
bookingData solidarity_service.CreateBookingSolidarityRequest
}
//List les conducteurs disponibles + Créer une réservation
func (h *ApplicationHandler) DriversJourney(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" && r.FormValue("date") != ""{
DepartureAddress := r.FormValue("departure");
DestinationAddress := r.FormValue("destination");
PickupDate := r.FormValue("date");
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 {
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,
},
}
h.Renderer.SolidarityServiceListAvailableDrivers(w, r, drivers, &BookingData.bookingData)
} else if r.Method == "POST" {
vars := mux.Vars(r)
beneficiaryID := vars["id"]
driverId := r.FormValue("driver_id")
id := uuid.New().String()
BookingData.bookingData.Booking.DriverId = driverId
BookingData.bookingData.Booking.PassengerId= beneficiaryID
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)
}else {
h.Renderer.CreateBookingHome(w, r)
}
}
func (h *ApplicationHandler) SolidarityService(w http.ResponseWriter, r *http.Request) {
accounts, err := h.services.GRPC.SolidarityService.GetAllPassengers(context.TODO(), &emptypb.Empty{})
drivers, err := h.services.GRPC.SolidarityService.GetAllDrivers(context.TODO(), &emptypb.Empty{})
bookings, err := h.services.GRPC.SolidarityService.GetAllBookingsSolidarity(context.TODO(), &emptypb.Empty{})
parcourmobAccounts, err := h.beneficiaries(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
}
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
h.Renderer.SolidarityService(w, r, accounts, drivers, parcourmobAccounts, bookings ,cacheid)
}
func (h *ApplicationHandler) CreateDriver(w http.ResponseWriter, r *http.Request) {
if r.Method== "POST" {
dataMap, err := parseBeneficiariesForm(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
data, err := structpb.NewValue(dataMap)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
userRequest := &mobilityaccounts.RegisterRequest{
Account: &mobilityaccounts.Account{
Namespace: "silvermobi",
Data: data.GetStructValue(),
},
}
resp, err := h.services.GRPC.MobilityAccounts.Register(context.TODO(), userRequest)
address := resp.Account.Data.GetFields()["address"].GetStructValue();
geometry := address.GetFields()["geometry"].GetStructValue();
coordinates:= geometry.GetFields()["coordinates"].GetListValue();
if len(coordinates.GetValues()) < 2{
fmt.Printf("Erreur lors de la récupération des coordonées : %v", err)
return
}
radiusStr := r.PostFormValue("radius")
radius, err := strconv.Atoi(radiusStr)
if err != nil {
fmt.Printf("Erreur lors de la conversion de radius : %v", err)
radius = 0
}
availabilitiesJSON := r.PostFormValue("availabilities")
var availabilities []solidarity_service.RegularAvailabilitySlot
jsonerr:= json.Unmarshal([]byte(availabilitiesJSON), &availabilities)
if jsonerr != nil {
fmt.Printf("Erreur lors de la conversion de availabilitiesJSON : %v", err)
}
driverRequest := solidarity_service.DriverRegularAvailabilities {
DriverRequest : &solidarity_service.DriverRequest {
DriverAddress: &solidarity_service.Feature{
Lat: coordinates.GetValues()[0].GetNumberValue(),
Long: coordinates.GetValues()[1].GetNumberValue(),
Address: "********",
},
DriverRadius: int32(radius),
Driver: &solidarity_service.User{
Id: resp.Account.Id,
Alias: r.PostFormValue("alias"),
FirstName: r.PostFormValue("first_name"),
LastName: r.PostFormValue("last_name"),
Grade: 1,
Picture: "h.png",
Gender: r.PostFormValue("gender"),
VerifiedIdentity: true, ///////// a Modifier !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
},
Preferences: &solidarity_service.Preferences{
Smoking: false,
Animals: false,
Music: false,
IsTalker: false,
LuggageSize: 100,
},
Car: &solidarity_service.Car{
Model: r.PostFormValue("model"),
Brand: r.PostFormValue("brand"),
},
},
DriverAvailabilities: []*solidarity_service.RegularAvailabilitySlot{},
}
for _, slot := range availabilities{
driverRequest.DriverAvailabilities = append( driverRequest.DriverAvailabilities, &solidarity_service.RegularAvailabilitySlot{
DayOfWeek: slot.DayOfWeek,
StartTime: slot.StartTime,
EndTime: slot.EndTime,
})
}
driverResponse, err := h.services.GRPC.SolidarityService.SetDriverRegularAvailabilities(context.TODO(), &driverRequest)
if err != nil {
fmt.Printf("erreur lors de la création du conducteur: ", err)
radius = 0
}
fmt.Println("driver: ", driverResponse)
}
h.Renderer.CreateDriver(w, r)
}

View File

@@ -45,7 +45,9 @@ func (h *ApplicationHandler) VehiclesManagementOverview(w http.ResponseWriter, r
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)
@@ -188,36 +190,10 @@ func (h *ApplicationHandler) VehiclesFleetDisplay(w http.ResponseWriter, r *http
w.WriteHeader(http.StatusInternalServerError)
return
}
// if len(resp.Vehicle.ToStorageType().Bookings) == 0 {
// fmt.Println("lol")
// }
// fmt.Println(resp.Vehicle.ToStorageType().Bookings)
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 {
@@ -467,27 +443,210 @@ 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) 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)
}

View File

@@ -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)
}

View File

@@ -5,6 +5,7 @@ import (
"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"
@@ -18,7 +19,6 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
vehicles := map[string]fleetsstorage.Vehicle{}
bookings := []fleetsstorage.Booking{}
reequest := &fleets.GetVehiclesRequest{
Namespaces: []string{"parcoursmob"},
}
@@ -45,6 +45,7 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
}
groups := map[string]groupsstorage.Group{}
admingroups, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), &groupsmanagement.GetGroupsRequest{
@@ -106,14 +107,31 @@ func (h *ExportsHandler) Bookings(w http.ResponseWriter, r *http.Request) {
bookedby := ""
if v, ok := b.Data["booked_by"].(map[string]any); ok {
if v2, ok := v["group"].(map[string]any); ok {
if v3, ok := v2["name"].(string); 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

14
main.go
View File

@@ -25,7 +25,7 @@ func main() {
}
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")
@@ -107,6 +107,9 @@ func main() {
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)
@@ -134,6 +137,12 @@ func main() {
application.HandleFunc("/support/", applicationHandler.SupportSend)
/*********************** CODE GROUP **************************/
//=================================silvermobi====================================
application.HandleFunc("/solidarity_service/", applicationHandler.SolidarityService)
application.HandleFunc("/solidarity_service/create/{id}", applicationHandler.DriversJourney)
application.HandleFunc("/solidarity_service/driver/create", applicationHandler.CreateDriver)
appGroup := application.PathPrefix("/group_module").Subrouter()
appGroup.HandleFunc("/", applicationHandler.Groups)
appGroup.HandleFunc("/groups", applicationHandler.CreateGroupModule)
@@ -162,6 +171,7 @@ func main() {
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)
@@ -169,7 +179,7 @@ func main() {
srv := &http.Server{
Handler: r,
Addr: address,
Addr: "0.0.0.0:9000",
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}

BIN
parcoursmob Executable file

Binary file not shown.

View File

@@ -5,7 +5,9 @@ import (
"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 +16,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 {
@@ -28,7 +40,19 @@ func (s BeneficiariesListState) JSONWithLimits(a int, b int) template.JS {
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,cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.list.files")
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
@@ -52,7 +76,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{}, solidarity_bookings_list []any) {
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
state.ViewState = map[string]any{
@@ -62,8 +86,9 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ
"file_types_map": file_types_map,
"documents": documents,
"organizations": organizations,
"event": event,
"bookingSolidarity" : solidarity_bookings_list,
}
renderer.Render("beneficiaries_display", w, r, files, state)
}

View File

@@ -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 {

View File

@@ -4,9 +4,10 @@ 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"
models "git.coopgo.io/coopgo-apps/parcoursmob/utils/models"
)
const journeysMenu = "journeys"
@@ -23,6 +24,7 @@ type BeneficiariesCovoiturageA struct {
Beneficiaries []any `json:"beneficiaries"`
}
func (s BeneficiariesCovoiturage) JSON() template.JS {
result, _ := json.Marshal(s)
return template.JS(result)
@@ -35,7 +37,7 @@ func (s BeneficiariesCovoiturage) JSONWithLimits(a int, b int) template.JS {
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) {
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools any, vehicles []any, searched bool, departure any, destination any, departuredate string, departuretime string, solidarity_results models.SolidarityTransport ) { //transitjourneys any,
files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
state.ViewState = map[string]any{
@@ -44,11 +46,11 @@ func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request,
"departuretime": departuretime,
"departure": departure,
"destination": destination,
"journeys": transitjourneys,
//"journeys": transitjourneys,
"carpools": carpools,
"vehicles": vehicles,
"solidarity_results": solidarity_results,
}
renderer.Render("journeys", w, r, files, state)
}

View File

@@ -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: "Transport solidaire",
Link: "/app/solidarity_service/",
Active: menuState == solidarityserviceMenu,
Icon: "hero:outline/map",
})
}
return RenderState{
IconSet: icons.NewIconSet(iconset),
Group: group,

View File

@@ -0,0 +1,127 @@
package renderer
import (
"encoding/json"
"html/template"
"net/http"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
solidarity_service "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
)
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"`
Bookings *solidarity_service.GetAllBookingsSolidarityResponse `json:"bookings"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
type BeneficiariesSolidarityListState struct {
Count int `json:"count"`
CacheId string `json:"cache_id"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
Drivers *solidarity_service.GetAllDriversResponse `json:"drivers"`
Bookings *solidarity_service.GetAllBookingsSolidarityResponse `json:"bookings"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
}
type SolidarityBookingsState struct {
Bookings *solidarity_service.CreateBookingSolidarityResponse `json:"bookings"`
Beneficiaries []mobilityaccountsstorage.Account `json:"beneficiaries"`
BeneficiariesSolidarity *solidarity_service.GetAllPassengersResponse `json:"beneficiariessolidarity"`
}
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, drivers *solidarity_service.GetAllDriversResponse, parcourmobAccounts []mobilityaccountsstorage.Account, bookings *solidarity_service.GetAllBookingsSolidarityResponse, cacheid string) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.list.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = BeneficiariesSolidarityListState{
Count: len(parcourmobAccounts),
CacheId: cacheid,
Beneficiaries: parcourmobAccounts,
BeneficiariesSolidarity: accounts,
Drivers: drivers,
Bookings: bookings,
}
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) CreateBookingHome(w http.ResponseWriter, r *http.Request ) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) SolidarityServiceBooking(w http.ResponseWriter, r *http.Request, bookings *solidarity_service.CreateBookingSolidarityResponse) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = SolidarityBookingsState{
Bookings: bookings,
}
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) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
state.ViewState = SolidarityListState{
Drivers: drivers,
}
renderer.Render("solidarity_service", w, r, files, state)
}
func (renderer *Renderer) CreateDriver(w http.ResponseWriter, r *http.Request) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_service.create_driver.files")
state := NewState(r, renderer.ThemeConfig, solidarityserviceMenu)
renderer.Render("solidarity_service", w, r, files, state)
}

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -5,7 +5,11 @@ 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 +17,13 @@ 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 +32,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 +56,27 @@ 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
}

View File

@@ -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
}

2
themes

Submodule themes updated: d6de19d8e2...db4c22699e

7
utils/models/models.go Normal file
View File

@@ -0,0 +1,7 @@
package internal
type SolidarityTransport struct {
Drivers []any
Beneficiaries []any
}

View File

@@ -1 +0,0 @@
package storage

View File

@@ -1,7 +1,6 @@
package storage
import (
"fmt"
"time"
"github.com/spf13/viper"
@@ -15,18 +14,7 @@ type KVHandler interface {
}
func NewKVHandler(cfg *viper.Viper) (KVHandler, error) {
cacheType := cfg.GetString("storage.kv.dbType")
switch cacheType {
case "etcd":
return NewEtcdHandler(cfg)
case "badger":
return NewBadgerHandler(cfg)
case "etcdGroupcache":
return NewGroupCacheHandler(cfg)
fmt.Println("here")
case "badgerGroupcache":
return NewGroupCacheHandler(cfg)
}
return NewEtcdHandler(cfg)
return nil, nil
}