refactor func maps

This commit is contained in:
Arnaud Delcasse 2025-09-30 22:59:35 +02:00
parent 20a3b6ed3b
commit a6f70a6e85
5 changed files with 38 additions and 87 deletions

2
go.mod
View File

@ -69,7 +69,6 @@ require (
require ( require (
git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss v0.0.0-20250429082239-a95cd6eb5523 // indirect git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss v0.0.0-20250429082239-a95cd6eb5523 // indirect
github.com/RoaringBitmap/roaring/v2 v2.4.5 // indirect github.com/RoaringBitmap/roaring/v2 v2.4.5 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/bits-and-blooms/bitset v1.22.0 // indirect github.com/bits-and-blooms/bitset v1.22.0 // indirect
github.com/blevesearch/bleve/v2 v2.5.2 // indirect github.com/blevesearch/bleve/v2 v2.5.2 // indirect
@ -94,7 +93,6 @@ require (
github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gorilla/schema v1.4.1 // indirect github.com/gorilla/schema v1.4.1 // indirect
github.com/mschoch/smat v0.2.0 // indirect github.com/mschoch/smat v0.2.0 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/sagikazarmark/locafero v0.9.0 // indirect github.com/sagikazarmark/locafero v0.9.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect
github.com/tidwall/geoindex v1.7.0 // indirect github.com/tidwall/geoindex v1.7.0 // indirect

12
go.sum
View File

@ -2,8 +2,6 @@ ariga.io/atlas v0.32.0 h1:y+77nueMrExLiKlz1CcPKh/nU7VSlWfBbwCShsJyvCw=
ariga.io/atlas v0.32.0/go.mod h1:Oe1xWPuu5q9LzyrWfbZmEZxFYeu4BHTyzfjeW2aZp/w= ariga.io/atlas v0.32.0/go.mod h1:Oe1xWPuu5q9LzyrWfbZmEZxFYeu4BHTyzfjeW2aZp/w=
git.coopgo.io/coopgo-platform/agenda v1.0.0 h1:rTHgva1JKKO0wAPlINegifMkHm+xOg3IWW4yQRy334w= git.coopgo.io/coopgo-platform/agenda v1.0.0 h1:rTHgva1JKKO0wAPlINegifMkHm+xOg3IWW4yQRy334w=
git.coopgo.io/coopgo-platform/agenda v1.0.0/go.mod h1:/hToSla0p6SeWn1zo1MDrfxdmo7RBdZDkbLqCVituIM= git.coopgo.io/coopgo-platform/agenda v1.0.0/go.mod h1:/hToSla0p6SeWn1zo1MDrfxdmo7RBdZDkbLqCVituIM=
git.coopgo.io/coopgo-platform/carpool-service v0.0.0-20250415082502-575b8129b727 h1:HdE8EO1CUhwGOTeNeG6dftWtxvZIHWA7SvxBAA7Ab1s=
git.coopgo.io/coopgo-platform/carpool-service v0.0.0-20250415082502-575b8129b727/go.mod h1:edaXmIta2b5SfK1OHG/02uRAXkKZqj7dSMQoeBxfUew=
git.coopgo.io/coopgo-platform/carpool-service v0.0.0-20250925043614-b7ac71741f43 h1:6gFe8+7tiAiUie7qCl4UaLv5QyUUtJvt23ju1Wa6Xg0= git.coopgo.io/coopgo-platform/carpool-service v0.0.0-20250925043614-b7ac71741f43 h1:6gFe8+7tiAiUie7qCl4UaLv5QyUUtJvt23ju1Wa6Xg0=
git.coopgo.io/coopgo-platform/carpool-service v0.0.0-20250925043614-b7ac71741f43/go.mod h1:J0vTvTd+NJ3dKcJ28Ca2xV7OMuglpJ9i4KPRb2SJqew= git.coopgo.io/coopgo-platform/carpool-service v0.0.0-20250925043614-b7ac71741f43/go.mod h1:J0vTvTd+NJ3dKcJ28Ca2xV7OMuglpJ9i4KPRb2SJqew=
git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss v0.0.0-20250429082239-a95cd6eb5523 h1:hXoUOEZ+umiyR0SzYbGacJxiUbW4puw4phmkfTVfqPU= git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss v0.0.0-20250429082239-a95cd6eb5523 h1:hXoUOEZ+umiyR0SzYbGacJxiUbW4puw4phmkfTVfqPU=
@ -20,8 +18,6 @@ git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee074
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee0746c/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA= git.coopgo.io/coopgo-platform/groups-management v0.0.0-20230310123255-5ef94ee0746c/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA=
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20230329105908-a76c0412a386 h1:v1JUdx8sknw2YYhFGz5cOAa1dEWNIBKvyiOpKr3RR+s= git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20230329105908-a76c0412a386 h1:v1JUdx8sknw2YYhFGz5cOAa1dEWNIBKvyiOpKr3RR+s=
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20230329105908-a76c0412a386/go.mod h1:1typNYtO+PQT6KG77vs/PUv0fO60/nbeSGZL2tt1LLg= git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20230329105908-a76c0412a386/go.mod h1:1typNYtO+PQT6KG77vs/PUv0fO60/nbeSGZL2tt1LLg=
git.coopgo.io/coopgo-platform/multimodal-routing v0.0.0-20250504230045-8680f560066a h1:Fl12RBdYDxYh7H2xluPhgTpaHKUNULWpsclBKNx2t8s=
git.coopgo.io/coopgo-platform/multimodal-routing v0.0.0-20250504230045-8680f560066a/go.mod h1:zDMfGVIvzuWV4Cw4bSi2kuEyMDbAfNfs7cGOAWNKfOo=
git.coopgo.io/coopgo-platform/multimodal-routing v0.0.0-20250925053957-63fc3e7c834f h1:uePG+xhXdFiOhSyoNjJ3ZElwe/cWRm/++6iUHseY3Q8= git.coopgo.io/coopgo-platform/multimodal-routing v0.0.0-20250925053957-63fc3e7c834f h1:uePG+xhXdFiOhSyoNjJ3ZElwe/cWRm/++6iUHseY3Q8=
git.coopgo.io/coopgo-platform/multimodal-routing v0.0.0-20250925053957-63fc3e7c834f/go.mod h1:zDMfGVIvzuWV4Cw4bSi2kuEyMDbAfNfs7cGOAWNKfOo= git.coopgo.io/coopgo-platform/multimodal-routing v0.0.0-20250925053957-63fc3e7c834f/go.mod h1:zDMfGVIvzuWV4Cw4bSi2kuEyMDbAfNfs7cGOAWNKfOo=
git.coopgo.io/coopgo-platform/payments v0.0.0-20250616162131-77f7b00b8fc3 h1:HGEo2E4IyprzshGKKeK7xMmorLNIGF8vbxa3zkBa+KM= git.coopgo.io/coopgo-platform/payments v0.0.0-20250616162131-77f7b00b8fc3 h1:HGEo2E4IyprzshGKKeK7xMmorLNIGF8vbxa3zkBa+KM=
@ -41,7 +37,6 @@ github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/RoaringBitmap/roaring/v2 v2.4.5 h1:uGrrMreGjvAtTBobc0g5IrW1D5ldxDQYe2JW2gggRdg= github.com/RoaringBitmap/roaring/v2 v2.4.5 h1:uGrrMreGjvAtTBobc0g5IrW1D5ldxDQYe2JW2gggRdg=
github.com/RoaringBitmap/roaring/v2 v2.4.5/go.mod h1:FiJcsfkGje/nZBZgCu0ZxCPOKD/hVXDS2dXi7/eUFE0= github.com/RoaringBitmap/roaring/v2 v2.4.5/go.mod h1:FiJcsfkGje/nZBZgCu0ZxCPOKD/hVXDS2dXi7/eUFE0=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
@ -50,8 +45,6 @@ github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZ
github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/arran4/golang-ical v0.3.1 h1:v13B3eQZ9VDHTAvT6M11vVzxYgcYmjyPBE2eAZl3VZk= github.com/arran4/golang-ical v0.3.1 h1:v13B3eQZ9VDHTAvT6M11vVzxYgcYmjyPBE2eAZl3VZk=
@ -97,7 +90,6 @@ github.com/blevesearch/zapx/v15 v15.4.2 h1:sWxpDE0QQOTjyxYbAVjt3+0ieu8NCE0fDRaFx
github.com/blevesearch/zapx/v15 v15.4.2/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw= github.com/blevesearch/zapx/v15 v15.4.2/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw=
github.com/blevesearch/zapx/v16 v16.2.4 h1:tGgfvleXTAkwsD5mEzgM3zCS/7pgocTCnO1oyAUjlww= github.com/blevesearch/zapx/v16 v16.2.4 h1:tGgfvleXTAkwsD5mEzgM3zCS/7pgocTCnO1oyAUjlww=
github.com/blevesearch/zapx/v16 v16.2.4/go.mod h1:Rti/REtuuMmzwsI8/C/qIzRaEoSK/wiFYw5e5ctUKKs= github.com/blevesearch/zapx/v16 v16.2.4/go.mod h1:Rti/REtuuMmzwsI8/C/qIzRaEoSK/wiFYw5e5ctUKKs=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0= github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
@ -186,7 +178,6 @@ github.com/huandu/xstrings v1.3.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
@ -245,8 +236,6 @@ github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
@ -292,7 +281,6 @@ github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4= github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=

View File

@ -758,10 +758,7 @@ func (h *ApplicationHandler) SolidarityTransportDriverJourney(w http.ResponseWri
return return
} }
passengerWalletBalance := float64(0) passengerWalletBalance := h.calculateWalletBalance(passenger)
if passenger.Data != nil {
passengerWalletBalance = h.calculateWalletBalance(passenger)
}
h.Renderer.SolidarityTransportDriverJourney(w, r, driverjourney, driver, passenger, beneficiaries, passengerWalletBalance) h.Renderer.SolidarityTransportDriverJourney(w, r, driverjourney, driver, passenger, beneficiaries, passengerWalletBalance)
} }
@ -837,10 +834,7 @@ func (h *ApplicationHandler) SolidarityTransportBookingDisplay(w http.ResponseWr
return return
} }
passengerWalletBalance := float64(0) passengerWalletBalance := h.calculateWalletBalance(passenger)
if passenger.Data != nil {
passengerWalletBalance = h.calculateWalletBalance(passenger)
}
h.Renderer.SolidarityTransportBookingDisplay(w, r, booking, driver, passenger, passengerWalletBalance) h.Renderer.SolidarityTransportBookingDisplay(w, r, booking, driver, passenger, passengerWalletBalance)
} }

View File

@ -5,9 +5,12 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"reflect"
"strings" "strings"
"time" "time"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
validatedprofile "git.coopgo.io/coopgo-apps/parcoursmob/utils/validated-profile"
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage" groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -148,6 +151,37 @@ func strval(v interface{}) string {
} }
} }
// GetTemplateFuncMap returns the common template functions for rendering
func GetTemplateFuncMap(group groupsstorage.Group, globalConfig *viper.Viper, fileStorage filestorage.FileStorage) template.FuncMap {
return template.FuncMap{
"moduleAvailable": ModuleAvailable(group, globalConfig),
"timeFrom": TimeFrom,
"timeFormat": TimeFormat,
"genderISO5218": GenderISO5218,
"dict": Dict,
"json": JSON,
"rawjson": RawJSON,
"unescapeHTML": UnescapeHTML,
"walkingLength": WalkingLength,
"divideFloat64": Divide[float64],
"divideInt": Divide[int],
"typeOf": reflect.TypeOf,
"shortDuration": ShortDuration,
"beneficiaryValidatedProfile": validatedprofile.ValidateProfile(globalConfig.Sub("modules.beneficiaries.validated_profile")),
"solidarityDriverValidatedProfile": validatedprofile.ValidateProfile(globalConfig.Sub("modules.solidarity_transport.drivers.validated_profile")),
"carpoolDriverValidatedProfile": validatedprofile.ValidateProfile(globalConfig.Sub("modules.organized_carpool.drivers.validated_profile")),
"beneficiaryDocuments": func(id string) []filestorage.FileInfo {
return fileStorage.List(filestorage.PREFIX_BENEFICIARIES + "/" + id)
},
"solidarityDocuments": func(id string) []filestorage.FileInfo {
return fileStorage.List(filestorage.PREFIX_SOLIDARITY_TRANSPORT_DRIVERS + "/" + id)
},
"carpoolDocuments": func(id string) []filestorage.FileInfo {
return fileStorage.List(filestorage.PREFIX_ORGANIZED_CARPOOL_DRIVERS + "/" + id)
},
}
}
func Divide[V int | float64](a, b V) V { func Divide[V int | float64](a, b V) V {
return a / b return a / b
} }

View File

@ -4,13 +4,10 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"net/http" "net/http"
"reflect"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/icons" "git.coopgo.io/coopgo-apps/parcoursmob/utils/icons"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification" "git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
validatedprofile "git.coopgo.io/coopgo-apps/parcoursmob/utils/validated-profile"
"git.coopgo.io/coopgo-platform/emailing" "git.coopgo.io/coopgo-platform/emailing"
"git.coopgo.io/coopgo-platform/groups-management/storage" "git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/coreos/go-oidc/v3/oidc" "github.com/coreos/go-oidc/v3/oidc"
@ -54,38 +51,7 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
t := template.New(name).Funcs( t := template.New(name).Funcs(GetTemplateFuncMap(state.Group, renderer.GlobalConfig, renderer.FileStorage))
template.FuncMap{
"moduleAvailable": ModuleAvailable(state.Group, renderer.GlobalConfig),
"timeFrom": TimeFrom,
"timeFormat": TimeFormat,
"genderISO5218": GenderISO5218,
"dict": Dict,
"json": JSON,
"rawjson": RawJSON,
"unescapeHTML": UnescapeHTML,
"walkingLength": WalkingLength,
"divideFloat64": Divide[float64],
"divideInt": Divide[int],
"typeOf": reflect.TypeOf,
"shortDuration": ShortDuration,
"beneficiaryValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.beneficiaries.validated_profile")),
"solidarityDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.solidarity_transport.drivers.validated_profile")),
"carpoolDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.organized_carpool.drivers.validated_profile")),
"beneficiaryDocuments": func(id string) []filestorage.FileInfo {
documents := renderer.FileStorage.List(filestorage.PREFIX_BENEFICIARIES + "/" + id)
return documents
},
"solidarityDocuments": func(id string) []filestorage.FileInfo {
documents := renderer.FileStorage.List(filestorage.PREFIX_SOLIDARITY_TRANSPORT_DRIVERS + "/" + id)
return documents
},
"carpoolDocuments": func(id string) []filestorage.FileInfo {
documents := renderer.FileStorage.List(filestorage.PREFIX_ORGANIZED_CARPOOL_DRIVERS + "/" + id)
return documents
},
},
)
t = template.Must(t.ParseFiles(prefixed_files...)) t = template.Must(t.ParseFiles(prefixed_files...))
err := t.ExecuteTemplate(w, "main", state) err := t.ExecuteTemplate(w, "main", state)
@ -101,36 +67,7 @@ func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
t := template.New(name).Funcs( t := template.New(name).Funcs(GetTemplateFuncMap(state.Group, renderer.GlobalConfig, renderer.FileStorage))
template.FuncMap{
"timeFrom": TimeFrom,
"timeFormat": TimeFormat,
"genderISO5218": GenderISO5218,
"dict": Dict,
"json": JSON,
"rawjson": RawJSON,
"unsescapeHTML": UnescapeHTML,
"divideFloat64": Divide[float64],
"divideInt": Divide[int],
"typeOf": reflect.TypeOf,
"shortDuration": ShortDuration,
"beneficiaryValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.beneficiaries.validated_profile")),
"solidarityDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.solidarity_transport.drivers.validated_profile")),
"carpoolDriverValidatedProfile": validatedprofile.ValidateProfile(renderer.GlobalConfig.Sub("modules.organized_carpool.drivers.validated_profile")),
"beneficiaryDocuments": func(id string) []filestorage.FileInfo {
documents := renderer.FileStorage.List(filestorage.PREFIX_BENEFICIARIES + "/" + id)
return documents
},
"solidarityDocuments": func(id string) []filestorage.FileInfo {
documents := renderer.FileStorage.List(filestorage.PREFIX_SOLIDARITY_TRANSPORT_DRIVERS + "/" + id)
return documents
},
"carpoolDocuments": func(id string) []filestorage.FileInfo {
documents := renderer.FileStorage.List(filestorage.PREFIX_ORGANIZED_CARPOOL_DRIVERS + "/" + id)
return documents
},
},
)
t = template.Must(t.ParseFiles(prefixed_files...)) t = template.Must(t.ParseFiles(prefixed_files...))
err := t.ExecuteTemplate(w, "main", state) err := t.ExecuteTemplate(w, "main", state)