initial commit

This commit is contained in:
Arnaud Delcasse 2025-03-05 00:30:53 +01:00
commit 9da7b99e5d
32 changed files with 4541 additions and 0 deletions

View File

@ -0,0 +1,65 @@
name: Build and Push Docker Image
on:
push:
tags:
- "*"
branches:
- main
- dev
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Install Docker
run: |
apt-get update
apt-get install -y docker.io
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{secrets.buildx_kubeconfig}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: kubernetes
driver-opts: |
namespace=gitea
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: git.coopgo.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract metadata (tags, labels) for Docker image
id: metadata
uses: docker/metadata-action@v3
with:
images: git.coopgo.io/${{gitea.repository}}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
flavor: |
latest=auto
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ steps.metadata.outputs.tags }}
build-args: |
ACCESS_TOKEN_USR=${{gitea.actor}}
ACCESS_TOKEN_PWD=${{gitea.token}}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.yaml

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
FROM golang:alpine as builder
ARG ACCESS_TOKEN_USR="nothing"
ARG ACCESS_TOKEN_PWD="nothing"
RUN apk add --no-cache ca-certificates tzdata git
WORKDIR /
# Create a netrc file using the credentials specified using --build-arg
RUN printf "machine git.coopgo.io\n\
login ${ACCESS_TOKEN_USR}\n\
password ${ACCESS_TOKEN_PWD}\n"\
>> ~/.netrc
RUN chmod 600 ~/.netrc
COPY . .
RUN go mod download && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /server /
EXPOSE 8080
ENTRYPOINT ["/server"]

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# COOPGO Solidarity Transport
COOPGO Solidarity Transport is a solidarity transport management microservice. It handles :
- driver availabilities declarations
- passenger journeys requests
- matching between passenger journeys requests and driver availabilities

50
config.go Normal file
View File

@ -0,0 +1,50 @@
package main
import (
"strings"
"github.com/spf13/viper"
)
func ReadConfig() (*viper.Viper, error) {
defaults := map[string]any{
"name": "COOPGO Solidarity Transport",
"dev_env": false,
"storage": map[string]any{
"db": map[string]any{
"type": "mongodb",
"mongodb": map[string]any{
"host": "localhost",
"port": 27017,
"db_name": "coopgo_platform",
"collections": map[string]any{
"drivers_regular_availabilities": "solidarity_drivers_regular_availabilities",
"bookings": "solidarity_bookings",
"driver_journeys": "solidarity_driver_journeys",
},
},
},
},
"services": map[string]any{
"grpc": map[string]any{
"enable": true,
"port": 8080,
},
},
"routing": map[string]any{
"type": "valhalla",
"base_url": "https://valhalla.coopgo.io",
},
}
v := viper.New()
for key, value := range defaults {
v.SetDefault(key, value)
}
v.SetConfigName("config")
v.AddConfigPath(".")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
err := v.ReadInConfig()
return v, err
}

52
go.mod Normal file
View File

@ -0,0 +1,52 @@
module git.coopgo.io/coopgo-platform/solidarity-transport
go 1.23.3
replace git.coopgo.io/coopgo-platform/routing-service => ../../coopgo-platform/routing-service/
require (
github.com/google/uuid v1.6.0
github.com/rs/zerolog v1.33.0
github.com/spf13/viper v1.19.0
go.mongodb.org/mongo-driver/v2 v2.1.0
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.35.2
)
require (
git.coopgo.io/coopgo-platform/routing-service v0.0.0-20240919052617-d03cd410081c // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/compress v1.17.2 // 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.19 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/paulmach/orb v0.11.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.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.6.0 // 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.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.mongodb.org/mongo-driver v1.11.4 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

209
go.sum Normal file
View File

@ -0,0 +1,209 @@
git.coopgo.io/coopgo-platform/routing-service v0.0.0-20240919052617-d03cd410081c h1:I0pJtlpW7Eloiro+VXVRzdQYJW9AMmjNIczBlROCX9Y=
git.coopgo.io/coopgo-platform/routing-service v0.0.0-20240919052617-d03cd410081c/go.mod h1:Nh7o15LlV0OuO9zxvJIs9FlelpeAaLYkXtFdgIkFrgg=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dvyukov/go-fuzz v0.0.0-20200318091601-be3528f3a813/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
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/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4=
github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU=
github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/twpayne/go-polyline v1.1.1 h1:/tSF1BR7rN4HWj4XKqvRUNrCiYVMCvywxTFVofvDV0w=
github.com/twpayne/go-polyline v1.1.1/go.mod h1:ybd9IWWivW/rlXPXuuckeKUyF3yrIim+iqA7kSl4NFY=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.11.4 h1:4ayjakA013OdpGyL2K3ZqylTac/rMjrJOMZ1EHizXas=
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
go.mongodb.org/mongo-driver/v2 v2.1.0 h1:/ELnVNjmfUKDsoBisXxuJL0noR9CfeUIrP7Yt3R+egg=
go.mongodb.org/mongo-driver/v2 v2.1.0/go.mod h1:AWiLRShSrk5RHQS3AEn3RL19rqOzVq49MCpWQ3x/huI=
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

41
handler/availabilities.go Normal file
View File

@ -0,0 +1,41 @@
package handler
import "git.coopgo.io/coopgo-platform/solidarity-transport/types"
func (h *Handler) AddRegularAvailability(driver string, day int, startTime string, endTime string) error {
availability := types.DriverRegularAvailability{
DriverId: driver,
Day: day,
StartTime: startTime,
EndTime: endTime,
}
if err := h.Storage.CreateDriverRegularAvailability(availability); err != nil {
return err
}
return nil
}
func (h *Handler) AddDriverRegularAvailabilities(availabilities []*types.DriverRegularAvailability) error {
if err := h.Storage.CreateDriverRegularAvailabilities(availabilities); err != nil {
return err
}
return nil
}
func (h *Handler) GetDriverRegularAvailabilities(driver string) ([]*types.DriverRegularAvailability, error) {
availabilities, err := h.Storage.GetDriverRegularAvailabilities(driver)
if err != nil {
return nil, err
}
return availabilities, nil
}
func (h *Handler) DeleteDriverRegularAvailabilities(driver string, availability string) error {
if err := h.Storage.DeleteDriverRegularAvailability(driver, availability); err != nil {
return err
}
return nil
}

73
handler/bookings.go Normal file
View File

@ -0,0 +1,73 @@
package handler
import (
"errors"
"time"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
)
func (h Handler) BookDriverJourney(passengerid string, driverid string, journeyid string) error {
journey, err := h.Storage.GetDriverJourney(journeyid)
if err != nil {
log.Error().Err(err).Msg("could not find driver journey")
return err
}
if journey.DriverId != driverid {
return errors.New("not authorized : journey id driver and driverid mismatch")
}
booking := types.Booking{
Id: uuid.NewString(),
GroupId: uuid.NewString(),
Status: "WAITING_CONFIRMATION",
PassengerId: passengerid,
DriverId: driverid,
Journey: journey,
}
if err := h.Storage.CreateBooking(booking); err != nil {
log.Error().Err(err).Msg("error creating booking")
return err
}
return nil
}
func (h Handler) GetBookings(startdate time.Time, enddate time.Time) ([]*types.Booking, error) {
res := []*types.Booking{}
bookings, err := h.Storage.GetAllBookings()
if err != nil {
log.Error().Err(err).Msg("error retrieving bookings")
return nil, err
}
for _, b := range bookings {
if b.Journey.DriverDepartureDate.After(startdate) && b.Journey.DriverDepartureDate.Before(enddate) {
res = append(res, b)
}
}
return res, nil
}
func (h Handler) GetBooking(id string) (*types.Booking, error) {
booking, err := h.Storage.GetBooking(id)
if err != nil {
log.Error().Err(err).Msg("could not get booking")
return nil, err
}
return booking, nil
}
func (h Handler) UpdateBookingStatus(bookingid string, newStatus string) error {
if err := h.Storage.UpdateBookingStatus(bookingid, newStatus); err != nil {
log.Error().Err(err).Msg("could not update booking")
return err
}
return nil
}

21
handler/handler.go Normal file
View File

@ -0,0 +1,21 @@
package handler
import (
"git.coopgo.io/coopgo-platform/routing-service"
"git.coopgo.io/coopgo-platform/solidarity-transport/storage"
"github.com/spf13/viper"
)
type Handler struct {
Config *viper.Viper
Storage storage.Storage
Routing routing.RoutingService
}
func NewSolidarityTransportHandler(cfg *viper.Viper, store storage.Storage, routing routing.RoutingService) (*Handler, error) {
return &Handler{
Config: cfg,
Storage: store,
Routing: routing,
}, nil
}

85
handler/journeys.go Normal file
View File

@ -0,0 +1,85 @@
package handler
import (
"errors"
"time"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/google/uuid"
"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"
"github.com/rs/zerolog/log"
)
func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson.Feature, departureDate time.Time) ([]*types.DriverJourney, error) {
day := int(departureDate.Weekday())
timeInDay := departureDate.Format("15:04")
driverJourneys := []*types.DriverJourney{}
// Get Availabilities
availabilities, err := h.Storage.GetRegularAvailabilities(day, timeInDay)
if err != nil {
log.Error().Err(err).Msg("error in GetRegularAvailabilities")
return nil, err
}
for _, a := range availabilities {
log.Debug().Any("availability", a).Msg("Availability found")
if a.Address != nil {
route, err := h.Routing.Route(
[]orb.Point{
a.Address.Point(),
departure.Point(),
arrival.Point(),
a.Address.Point(),
},
)
if err != nil {
log.Error().Err(err).Msg("failedcomputing route request")
continue
}
log.Debug().Any("route", route).Msg("debug route")
driverJourney := &types.DriverJourney{
Id: uuid.NewString(),
DriverId: a.DriverId,
PassengerPickup: departure,
PassengerDrop: arrival,
PassengerDistance: int64(route.Legs[1].Distance),
DriverDeparture: a.Address,
DriverArrival: a.Address,
DriverDistance: int64(route.Distance),
Duration: route.Legs[1].Duration,
JourneyPolyline: route.Polyline,
PassengerPickupDate: departureDate,
DriverDepartureDate: departureDate.Add(-1 * route.Legs[0].Duration),
Price: types.SolidarityTransportPrice{
Currency: "EUR",
Amount: 0,
},
}
driverJourneys = append(driverJourneys, driverJourney)
}
}
if err := h.Storage.PushDriverJourneys(driverJourneys); err != nil {
log.Error().Err(err).Msg("error storing driver journeys in database")
}
return driverJourneys, nil
}
func (h Handler) GetDriverJourney(driverid string, journeyid string) (*types.DriverJourney, error) {
journey, err := h.Storage.GetDriverJourney(journeyid)
if err != nil {
log.Error().Err(err).Msg("error retrieving journey")
return nil, err
}
if driverid != journey.DriverId {
return nil, errors.New("not allowed, driver id mismatch")
}
return journey, nil
}

62
main.go Normal file
View File

@ -0,0 +1,62 @@
package main
import (
"os"
routing "git.coopgo.io/coopgo-platform/routing-service"
"git.coopgo.io/coopgo-platform/solidarity-transport/handler"
grpcserver "git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/server"
"git.coopgo.io/coopgo-platform/solidarity-transport/storage"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
cfg, err := ReadConfig()
if err != nil {
panic(err)
}
var (
service_name = cfg.GetString("name")
grpc_enable = cfg.GetBool("services.grpc.enable")
dev_env = cfg.GetBool("dev_env")
routing_service_type = cfg.GetString("routing.type")
valhalla_base_url = cfg.GetString("routing.valhalla.base_url")
)
if dev_env {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
log.Info().Msg("Running " + service_name)
storage, err := storage.NewStorage(cfg)
if err != nil {
log.Fatal().Err(err).Msg("could not initiate storage")
return
}
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
}
handler, err := handler.NewSolidarityTransportHandler(cfg, storage, routing)
if err != nil {
log.Fatal().Err(err).Msg("could not initialize solidarity transport handler")
return
}
failed := make(chan error)
if grpc_enable {
log.Info().Msg("Running grpc server")
go grpcserver.Run(failed, cfg, handler)
}
err = <-failed
log.Fatal().Err(err).Msg("Terminating")
}

View File

@ -0,0 +1,7 @@
# Protocol buffer definition
From this directory, generate protocol buffer server and client boilerplate using :
protoc --go_out=paths=source_relative:./gen --go-grpc_out=paths=source_relative:./gen ./*.proto
(You need some dependencies like protoc, protoc-gen-go ... To get them easily, you can use the <https://git.coopgo.io/coopgo-platform/dev-environment> nix shell)

View File

@ -0,0 +1,727 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.34.1
// protoc v4.24.4
// source: solidarity-transport-types.proto
package gen
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type GeoJsonFeature struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Serialized string `protobuf:"bytes,1,opt,name=serialized,proto3" json:"serialized,omitempty"`
}
func (x *GeoJsonFeature) Reset() {
*x = GeoJsonFeature{}
if protoimpl.UnsafeEnabled {
mi := &file_solidarity_transport_types_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GeoJsonFeature) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GeoJsonFeature) ProtoMessage() {}
func (x *GeoJsonFeature) ProtoReflect() protoreflect.Message {
mi := &file_solidarity_transport_types_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GeoJsonFeature.ProtoReflect.Descriptor instead.
func (*GeoJsonFeature) Descriptor() ([]byte, []int) {
return file_solidarity_transport_types_proto_rawDescGZIP(), []int{0}
}
func (x *GeoJsonFeature) GetSerialized() string {
if x != nil {
return x.Serialized
}
return ""
}
type GeoJsonFeatureCollection struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Serialized string `protobuf:"bytes,1,opt,name=serialized,proto3" json:"serialized,omitempty"`
}
func (x *GeoJsonFeatureCollection) Reset() {
*x = GeoJsonFeatureCollection{}
if protoimpl.UnsafeEnabled {
mi := &file_solidarity_transport_types_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GeoJsonFeatureCollection) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GeoJsonFeatureCollection) ProtoMessage() {}
func (x *GeoJsonFeatureCollection) ProtoReflect() protoreflect.Message {
mi := &file_solidarity_transport_types_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GeoJsonFeatureCollection.ProtoReflect.Descriptor instead.
func (*GeoJsonFeatureCollection) Descriptor() ([]byte, []int) {
return file_solidarity_transport_types_proto_rawDescGZIP(), []int{1}
}
func (x *GeoJsonFeatureCollection) GetSerialized() string {
if x != nil {
return x.Serialized
}
return ""
}
type DriverRegularAvailability struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
DriverId string `protobuf:"bytes,2,opt,name=driver_id,json=driverId,proto3" json:"driver_id,omitempty"`
Day int32 `protobuf:"varint,3,opt,name=day,proto3" json:"day,omitempty"`
StartTime string `protobuf:"bytes,4,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"`
EndTime string `protobuf:"bytes,5,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty"`
Address *GeoJsonFeature `protobuf:"bytes,6,opt,name=address,proto3" json:"address,omitempty"`
}
func (x *DriverRegularAvailability) Reset() {
*x = DriverRegularAvailability{}
if protoimpl.UnsafeEnabled {
mi := &file_solidarity_transport_types_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DriverRegularAvailability) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DriverRegularAvailability) ProtoMessage() {}
func (x *DriverRegularAvailability) ProtoReflect() protoreflect.Message {
mi := &file_solidarity_transport_types_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DriverRegularAvailability.ProtoReflect.Descriptor instead.
func (*DriverRegularAvailability) Descriptor() ([]byte, []int) {
return file_solidarity_transport_types_proto_rawDescGZIP(), []int{2}
}
func (x *DriverRegularAvailability) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *DriverRegularAvailability) GetDriverId() string {
if x != nil {
return x.DriverId
}
return ""
}
func (x *DriverRegularAvailability) GetDay() int32 {
if x != nil {
return x.Day
}
return 0
}
func (x *DriverRegularAvailability) GetStartTime() string {
if x != nil {
return x.StartTime
}
return ""
}
func (x *DriverRegularAvailability) GetEndTime() string {
if x != nil {
return x.EndTime
}
return ""
}
func (x *DriverRegularAvailability) GetAddress() *GeoJsonFeature {
if x != nil {
return x.Address
}
return nil
}
type SolidarityTransportDriverJourney struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
DriverId string `protobuf:"bytes,2,opt,name=driver_id,json=driverId,proto3" json:"driver_id,omitempty"`
PassengerPickup *GeoJsonFeature `protobuf:"bytes,3,opt,name=passenger_pickup,json=passengerPickup,proto3" json:"passenger_pickup,omitempty"`
PassengerDrop *GeoJsonFeature `protobuf:"bytes,4,opt,name=passenger_drop,json=passengerDrop,proto3" json:"passenger_drop,omitempty"`
PassengerDistance int64 `protobuf:"varint,5,opt,name=passenger_distance,json=passengerDistance,proto3" json:"passenger_distance,omitempty"`
DriverDeparture *GeoJsonFeature `protobuf:"bytes,6,opt,name=driver_departure,json=driverDeparture,proto3" json:"driver_departure,omitempty"`
DriverArrival *GeoJsonFeature `protobuf:"bytes,7,opt,name=driver_arrival,json=driverArrival,proto3" json:"driver_arrival,omitempty"`
DriverDistance int64 `protobuf:"varint,8,opt,name=driver_distance,json=driverDistance,proto3" json:"driver_distance,omitempty"`
Duration int64 `protobuf:"varint,9,opt,name=duration,proto3" json:"duration,omitempty"`
JourneyPolyline *string `protobuf:"bytes,10,opt,name=journey_polyline,json=journeyPolyline,proto3,oneof" json:"journey_polyline,omitempty"`
PassengerPickupDate *timestamppb.Timestamp `protobuf:"bytes,11,opt,name=passenger_pickup_date,json=passengerPickupDate,proto3" json:"passenger_pickup_date,omitempty"`
DriverDepartureDate *timestamppb.Timestamp `protobuf:"bytes,12,opt,name=driver_departure_date,json=driverDepartureDate,proto3,oneof" json:"driver_departure_date,omitempty"`
Price *SolidarityTransportPrice `protobuf:"bytes,13,opt,name=price,proto3,oneof" json:"price,omitempty"`
}
func (x *SolidarityTransportDriverJourney) Reset() {
*x = SolidarityTransportDriverJourney{}
if protoimpl.UnsafeEnabled {
mi := &file_solidarity_transport_types_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SolidarityTransportDriverJourney) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SolidarityTransportDriverJourney) ProtoMessage() {}
func (x *SolidarityTransportDriverJourney) ProtoReflect() protoreflect.Message {
mi := &file_solidarity_transport_types_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SolidarityTransportDriverJourney.ProtoReflect.Descriptor instead.
func (*SolidarityTransportDriverJourney) Descriptor() ([]byte, []int) {
return file_solidarity_transport_types_proto_rawDescGZIP(), []int{3}
}
func (x *SolidarityTransportDriverJourney) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *SolidarityTransportDriverJourney) GetDriverId() string {
if x != nil {
return x.DriverId
}
return ""
}
func (x *SolidarityTransportDriverJourney) GetPassengerPickup() *GeoJsonFeature {
if x != nil {
return x.PassengerPickup
}
return nil
}
func (x *SolidarityTransportDriverJourney) GetPassengerDrop() *GeoJsonFeature {
if x != nil {
return x.PassengerDrop
}
return nil
}
func (x *SolidarityTransportDriverJourney) GetPassengerDistance() int64 {
if x != nil {
return x.PassengerDistance
}
return 0
}
func (x *SolidarityTransportDriverJourney) GetDriverDeparture() *GeoJsonFeature {
if x != nil {
return x.DriverDeparture
}
return nil
}
func (x *SolidarityTransportDriverJourney) GetDriverArrival() *GeoJsonFeature {
if x != nil {
return x.DriverArrival
}
return nil
}
func (x *SolidarityTransportDriverJourney) GetDriverDistance() int64 {
if x != nil {
return x.DriverDistance
}
return 0
}
func (x *SolidarityTransportDriverJourney) GetDuration() int64 {
if x != nil {
return x.Duration
}
return 0
}
func (x *SolidarityTransportDriverJourney) GetJourneyPolyline() string {
if x != nil && x.JourneyPolyline != nil {
return *x.JourneyPolyline
}
return ""
}
func (x *SolidarityTransportDriverJourney) GetPassengerPickupDate() *timestamppb.Timestamp {
if x != nil {
return x.PassengerPickupDate
}
return nil
}
func (x *SolidarityTransportDriverJourney) GetDriverDepartureDate() *timestamppb.Timestamp {
if x != nil {
return x.DriverDepartureDate
}
return nil
}
func (x *SolidarityTransportDriverJourney) GetPrice() *SolidarityTransportPrice {
if x != nil {
return x.Price
}
return nil
}
type SolidarityTransportPrice struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Amount float64 `protobuf:"fixed64,1,opt,name=amount,proto3" json:"amount,omitempty"`
Currency string `protobuf:"bytes,2,opt,name=currency,proto3" json:"currency,omitempty"`
}
func (x *SolidarityTransportPrice) Reset() {
*x = SolidarityTransportPrice{}
if protoimpl.UnsafeEnabled {
mi := &file_solidarity_transport_types_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SolidarityTransportPrice) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SolidarityTransportPrice) ProtoMessage() {}
func (x *SolidarityTransportPrice) ProtoReflect() protoreflect.Message {
mi := &file_solidarity_transport_types_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SolidarityTransportPrice.ProtoReflect.Descriptor instead.
func (*SolidarityTransportPrice) Descriptor() ([]byte, []int) {
return file_solidarity_transport_types_proto_rawDescGZIP(), []int{4}
}
func (x *SolidarityTransportPrice) GetAmount() float64 {
if x != nil {
return x.Amount
}
return 0
}
func (x *SolidarityTransportPrice) GetCurrency() string {
if x != nil {
return x.Currency
}
return ""
}
type SolidarityTransportBooking struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
GroupId string `protobuf:"bytes,2,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"`
DriverId string `protobuf:"bytes,3,opt,name=driver_id,json=driverId,proto3" json:"driver_id,omitempty"`
PassengerId string `protobuf:"bytes,4,opt,name=passenger_id,json=passengerId,proto3" json:"passenger_id,omitempty"`
Status string `protobuf:"bytes,5,opt,name=status,proto3" json:"status,omitempty"`
Journey *SolidarityTransportDriverJourney `protobuf:"bytes,10,opt,name=journey,proto3" json:"journey,omitempty"`
}
func (x *SolidarityTransportBooking) Reset() {
*x = SolidarityTransportBooking{}
if protoimpl.UnsafeEnabled {
mi := &file_solidarity_transport_types_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SolidarityTransportBooking) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SolidarityTransportBooking) ProtoMessage() {}
func (x *SolidarityTransportBooking) ProtoReflect() protoreflect.Message {
mi := &file_solidarity_transport_types_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SolidarityTransportBooking.ProtoReflect.Descriptor instead.
func (*SolidarityTransportBooking) Descriptor() ([]byte, []int) {
return file_solidarity_transport_types_proto_rawDescGZIP(), []int{5}
}
func (x *SolidarityTransportBooking) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *SolidarityTransportBooking) GetGroupId() string {
if x != nil {
return x.GroupId
}
return ""
}
func (x *SolidarityTransportBooking) GetDriverId() string {
if x != nil {
return x.DriverId
}
return ""
}
func (x *SolidarityTransportBooking) GetPassengerId() string {
if x != nil {
return x.PassengerId
}
return ""
}
func (x *SolidarityTransportBooking) GetStatus() string {
if x != nil {
return x.Status
}
return ""
}
func (x *SolidarityTransportBooking) GetJourney() *SolidarityTransportDriverJourney {
if x != nil {
return x.Journey
}
return nil
}
var File_solidarity_transport_types_proto protoreflect.FileDescriptor
var file_solidarity_transport_types_proto_rawDesc = []byte{
0x0a, 0x20, 0x73, 0x6f, 0x6c, 0x69, 0x64, 0x61, 0x72, 0x69, 0x74, 0x79, 0x2d, 0x74, 0x72, 0x61,
0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x22, 0x30, 0x0a, 0x0e, 0x47, 0x65, 0x6f, 0x4a, 0x73, 0x6f, 0x6e, 0x46, 0x65,
0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69,
0x7a, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x69, 0x61,
0x6c, 0x69, 0x7a, 0x65, 0x64, 0x22, 0x3a, 0x0a, 0x18, 0x47, 0x65, 0x6f, 0x4a, 0x73, 0x6f, 0x6e,
0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f,
0x6e, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65,
0x64, 0x22, 0xbf, 0x01, 0x0a, 0x19, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0x52, 0x65, 0x67, 0x75,
0x6c, 0x61, 0x72, 0x41, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
0x1b, 0x0a, 0x09, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03,
0x64, 0x61, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x64, 0x61, 0x79, 0x12, 0x1d,
0x0a, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x19, 0x0a,
0x08, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72,
0x65, 0x73, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x47, 0x65, 0x6f, 0x4a,
0x73, 0x6f, 0x6e, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72,
0x65, 0x73, 0x73, 0x22, 0xef, 0x05, 0x0a, 0x20, 0x53, 0x6f, 0x6c, 0x69, 0x64, 0x61, 0x72, 0x69,
0x74, 0x79, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x72, 0x69, 0x76, 0x65,
0x72, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x65, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x72, 0x69, 0x76,
0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x72, 0x69,
0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x3a, 0x0a, 0x10, 0x70, 0x61, 0x73, 0x73, 0x65, 0x6e, 0x67,
0x65, 0x72, 0x5f, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0f, 0x2e, 0x47, 0x65, 0x6f, 0x4a, 0x73, 0x6f, 0x6e, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65,
0x52, 0x0f, 0x70, 0x61, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x50, 0x69, 0x63, 0x6b, 0x75,
0x70, 0x12, 0x36, 0x0a, 0x0e, 0x70, 0x61, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x64,
0x72, 0x6f, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x47, 0x65, 0x6f, 0x4a,
0x73, 0x6f, 0x6e, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x0d, 0x70, 0x61, 0x73, 0x73,
0x65, 0x6e, 0x67, 0x65, 0x72, 0x44, 0x72, 0x6f, 0x70, 0x12, 0x2d, 0x0a, 0x12, 0x70, 0x61, 0x73,
0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x64, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18,
0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x70, 0x61, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72,
0x44, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x3a, 0x0a, 0x10, 0x64, 0x72, 0x69, 0x76,
0x65, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x75, 0x72, 0x65, 0x18, 0x06, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x47, 0x65, 0x6f, 0x4a, 0x73, 0x6f, 0x6e, 0x46, 0x65, 0x61, 0x74,
0x75, 0x72, 0x65, 0x52, 0x0f, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x44, 0x65, 0x70, 0x61, 0x72,
0x74, 0x75, 0x72, 0x65, 0x12, 0x36, 0x0a, 0x0e, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x5f, 0x61,
0x72, 0x72, 0x69, 0x76, 0x61, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x47,
0x65, 0x6f, 0x4a, 0x73, 0x6f, 0x6e, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x0d, 0x64,
0x72, 0x69, 0x76, 0x65, 0x72, 0x41, 0x72, 0x72, 0x69, 0x76, 0x61, 0x6c, 0x12, 0x27, 0x0a, 0x0f,
0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x5f, 0x64, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18,
0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x44, 0x69, 0x73,
0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x12, 0x2e, 0x0a, 0x10, 0x6a, 0x6f, 0x75, 0x72, 0x6e, 0x65, 0x79, 0x5f, 0x70, 0x6f, 0x6c,
0x79, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0f, 0x6a,
0x6f, 0x75, 0x72, 0x6e, 0x65, 0x79, 0x50, 0x6f, 0x6c, 0x79, 0x6c, 0x69, 0x6e, 0x65, 0x88, 0x01,
0x01, 0x12, 0x4e, 0x0a, 0x15, 0x70, 0x61, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x70,
0x69, 0x63, 0x6b, 0x75, 0x70, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x13, 0x70, 0x61,
0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x44, 0x61, 0x74,
0x65, 0x12, 0x53, 0x0a, 0x15, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x61,
0x72, 0x74, 0x75, 0x72, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x48, 0x01, 0x52, 0x13,
0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x44, 0x65, 0x70, 0x61, 0x72, 0x74, 0x75, 0x72, 0x65, 0x44,
0x61, 0x74, 0x65, 0x88, 0x01, 0x01, 0x12, 0x34, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18,
0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x53, 0x6f, 0x6c, 0x69, 0x64, 0x61, 0x72, 0x69,
0x74, 0x79, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x50, 0x72, 0x69, 0x63, 0x65,
0x48, 0x02, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x88, 0x01, 0x01, 0x42, 0x13, 0x0a, 0x11,
0x5f, 0x6a, 0x6f, 0x75, 0x72, 0x6e, 0x65, 0x79, 0x5f, 0x70, 0x6f, 0x6c, 0x79, 0x6c, 0x69, 0x6e,
0x65, 0x42, 0x18, 0x0a, 0x16, 0x5f, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x5f, 0x64, 0x65, 0x70,
0x61, 0x72, 0x74, 0x75, 0x72, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x65, 0x42, 0x08, 0x0a, 0x06, 0x5f,
0x70, 0x72, 0x69, 0x63, 0x65, 0x22, 0x4e, 0x0a, 0x18, 0x53, 0x6f, 0x6c, 0x69, 0x64, 0x61, 0x72,
0x69, 0x74, 0x79, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x50, 0x72, 0x69, 0x63,
0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x75, 0x72,
0x72, 0x65, 0x6e, 0x63, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x75, 0x72,
0x72, 0x65, 0x6e, 0x63, 0x79, 0x22, 0xdc, 0x01, 0x0a, 0x1a, 0x53, 0x6f, 0x6c, 0x69, 0x64, 0x61,
0x72, 0x69, 0x74, 0x79, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x6f, 0x6f,
0x6b, 0x69, 0x6e, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x69, 0x64,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x64, 0x12,
0x1b, 0x0a, 0x09, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c,
0x70, 0x61, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0b, 0x70, 0x61, 0x73, 0x73, 0x65, 0x6e, 0x67, 0x65, 0x72, 0x49, 0x64, 0x12,
0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x3b, 0x0a, 0x07, 0x6a, 0x6f, 0x75, 0x72, 0x6e,
0x65, 0x79, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x53, 0x6f, 0x6c, 0x69, 0x64,
0x61, 0x72, 0x69, 0x74, 0x79, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x72,
0x69, 0x76, 0x65, 0x72, 0x4a, 0x6f, 0x75, 0x72, 0x6e, 0x65, 0x79, 0x52, 0x07, 0x6a, 0x6f, 0x75,
0x72, 0x6e, 0x65, 0x79, 0x42, 0x4b, 0x5a, 0x49, 0x67, 0x69, 0x74, 0x2e, 0x63, 0x6f, 0x6f, 0x70,
0x67, 0x6f, 0x2e, 0x69, 0x6f, 0x2f, 0x63, 0x6f, 0x6f, 0x70, 0x67, 0x6f, 0x2d, 0x70, 0x6c, 0x61,
0x74, 0x66, 0x6f, 0x72, 0x6d, 0x2f, 0x73, 0x6f, 0x6c, 0x69, 0x64, 0x61, 0x72, 0x69, 0x74, 0x79,
0x2d, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65,
0x72, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65,
0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_solidarity_transport_types_proto_rawDescOnce sync.Once
file_solidarity_transport_types_proto_rawDescData = file_solidarity_transport_types_proto_rawDesc
)
func file_solidarity_transport_types_proto_rawDescGZIP() []byte {
file_solidarity_transport_types_proto_rawDescOnce.Do(func() {
file_solidarity_transport_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_solidarity_transport_types_proto_rawDescData)
})
return file_solidarity_transport_types_proto_rawDescData
}
var file_solidarity_transport_types_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_solidarity_transport_types_proto_goTypes = []interface{}{
(*GeoJsonFeature)(nil), // 0: GeoJsonFeature
(*GeoJsonFeatureCollection)(nil), // 1: GeoJsonFeatureCollection
(*DriverRegularAvailability)(nil), // 2: DriverRegularAvailability
(*SolidarityTransportDriverJourney)(nil), // 3: SolidarityTransportDriverJourney
(*SolidarityTransportPrice)(nil), // 4: SolidarityTransportPrice
(*SolidarityTransportBooking)(nil), // 5: SolidarityTransportBooking
(*timestamppb.Timestamp)(nil), // 6: google.protobuf.Timestamp
}
var file_solidarity_transport_types_proto_depIdxs = []int32{
0, // 0: DriverRegularAvailability.address:type_name -> GeoJsonFeature
0, // 1: SolidarityTransportDriverJourney.passenger_pickup:type_name -> GeoJsonFeature
0, // 2: SolidarityTransportDriverJourney.passenger_drop:type_name -> GeoJsonFeature
0, // 3: SolidarityTransportDriverJourney.driver_departure:type_name -> GeoJsonFeature
0, // 4: SolidarityTransportDriverJourney.driver_arrival:type_name -> GeoJsonFeature
6, // 5: SolidarityTransportDriverJourney.passenger_pickup_date:type_name -> google.protobuf.Timestamp
6, // 6: SolidarityTransportDriverJourney.driver_departure_date:type_name -> google.protobuf.Timestamp
4, // 7: SolidarityTransportDriverJourney.price:type_name -> SolidarityTransportPrice
3, // 8: SolidarityTransportBooking.journey:type_name -> SolidarityTransportDriverJourney
9, // [9:9] is the sub-list for method output_type
9, // [9:9] is the sub-list for method input_type
9, // [9:9] is the sub-list for extension type_name
9, // [9:9] is the sub-list for extension extendee
0, // [0:9] is the sub-list for field type_name
}
func init() { file_solidarity_transport_types_proto_init() }
func file_solidarity_transport_types_proto_init() {
if File_solidarity_transport_types_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_solidarity_transport_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GeoJsonFeature); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_solidarity_transport_types_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GeoJsonFeatureCollection); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_solidarity_transport_types_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DriverRegularAvailability); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_solidarity_transport_types_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SolidarityTransportDriverJourney); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_solidarity_transport_types_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SolidarityTransportPrice); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_solidarity_transport_types_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SolidarityTransportBooking); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_solidarity_transport_types_proto_msgTypes[3].OneofWrappers = []interface{}{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_solidarity_transport_types_proto_rawDesc,
NumEnums: 0,
NumMessages: 6,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_solidarity_transport_types_proto_goTypes,
DependencyIndexes: file_solidarity_transport_types_proto_depIdxs,
MessageInfos: file_solidarity_transport_types_proto_msgTypes,
}.Build()
File_solidarity_transport_types_proto = out.File
file_solidarity_transport_types_proto_rawDesc = nil
file_solidarity_transport_types_proto_goTypes = nil
file_solidarity_transport_types_proto_depIdxs = nil
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,448 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc v4.24.4
// source: solidarity-transport.proto
package gen
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
SolidarityTransport_AddDriverRegularAvailability_FullMethodName = "/SolidarityTransport/AddDriverRegularAvailability"
SolidarityTransport_AddDriverRegularAvailabilities_FullMethodName = "/SolidarityTransport/AddDriverRegularAvailabilities"
SolidarityTransport_GetDriverRegularAvailabilities_FullMethodName = "/SolidarityTransport/GetDriverRegularAvailabilities"
SolidarityTransport_DeleteDriverRegularAvailability_FullMethodName = "/SolidarityTransport/DeleteDriverRegularAvailability"
SolidarityTransport_GetDriverJourneys_FullMethodName = "/SolidarityTransport/GetDriverJourneys"
SolidarityTransport_GetDriverJourney_FullMethodName = "/SolidarityTransport/GetDriverJourney"
SolidarityTransport_BookDriverJourney_FullMethodName = "/SolidarityTransport/BookDriverJourney"
SolidarityTransport_GetSolidarityTransportBookings_FullMethodName = "/SolidarityTransport/GetSolidarityTransportBookings"
SolidarityTransport_GetSolidarityTransportBooking_FullMethodName = "/SolidarityTransport/GetSolidarityTransportBooking"
SolidarityTransport_UpdateSolidarityTransportBookingStatus_FullMethodName = "/SolidarityTransport/UpdateSolidarityTransportBookingStatus"
)
// SolidarityTransportClient is the client API for SolidarityTransport service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SolidarityTransportClient interface {
// Availabilities management
AddDriverRegularAvailability(ctx context.Context, in *AddDriverRegularAvailabilityRequest, opts ...grpc.CallOption) (*AddDriverRegularAvailabilityResponse, error)
AddDriverRegularAvailabilities(ctx context.Context, in *AddDriverRegularAvailabilitiesRequest, opts ...grpc.CallOption) (*AddDriverRegularAvailabilitiesResponse, error)
GetDriverRegularAvailabilities(ctx context.Context, in *GetDriverRegularAvailabilitiesRequest, opts ...grpc.CallOption) (*GetDriverRegularAvailabilitiesResponse, error)
DeleteDriverRegularAvailability(ctx context.Context, in *DeleteDriverRegularAvailabilityRequest, opts ...grpc.CallOption) (*DeleteDriverRegularAvailabilityResponse, error)
// Search / Journeys
GetDriverJourneys(ctx context.Context, in *GetDriverJourneysRequest, opts ...grpc.CallOption) (*GetDriverJourneysResponse, error)
GetDriverJourney(ctx context.Context, in *GetDriverJourneyRequest, opts ...grpc.CallOption) (*GetDriverJourneyResponse, error)
// Booking flows
BookDriverJourney(ctx context.Context, in *BookDriverJourneyRequest, opts ...grpc.CallOption) (*BookDriverJourneyResponse, error)
GetSolidarityTransportBookings(ctx context.Context, in *GetSolidarityTransportBookingsRequest, opts ...grpc.CallOption) (*GetSolidarityTransportBookingsResponse, error)
GetSolidarityTransportBooking(ctx context.Context, in *GetSolidarityTransportBookingRequest, opts ...grpc.CallOption) (*GetSolidarityTransportBookingResponse, error)
UpdateSolidarityTransportBookingStatus(ctx context.Context, in *UpdateSolidarityTransportBookingStatusRequest, opts ...grpc.CallOption) (*UpdateSolidarityTransportBookingStatusResponse, error)
}
type solidarityTransportClient struct {
cc grpc.ClientConnInterface
}
func NewSolidarityTransportClient(cc grpc.ClientConnInterface) SolidarityTransportClient {
return &solidarityTransportClient{cc}
}
func (c *solidarityTransportClient) AddDriverRegularAvailability(ctx context.Context, in *AddDriverRegularAvailabilityRequest, opts ...grpc.CallOption) (*AddDriverRegularAvailabilityResponse, error) {
out := new(AddDriverRegularAvailabilityResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_AddDriverRegularAvailability_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) AddDriverRegularAvailabilities(ctx context.Context, in *AddDriverRegularAvailabilitiesRequest, opts ...grpc.CallOption) (*AddDriverRegularAvailabilitiesResponse, error) {
out := new(AddDriverRegularAvailabilitiesResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_AddDriverRegularAvailabilities_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) GetDriverRegularAvailabilities(ctx context.Context, in *GetDriverRegularAvailabilitiesRequest, opts ...grpc.CallOption) (*GetDriverRegularAvailabilitiesResponse, error) {
out := new(GetDriverRegularAvailabilitiesResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_GetDriverRegularAvailabilities_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) DeleteDriverRegularAvailability(ctx context.Context, in *DeleteDriverRegularAvailabilityRequest, opts ...grpc.CallOption) (*DeleteDriverRegularAvailabilityResponse, error) {
out := new(DeleteDriverRegularAvailabilityResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_DeleteDriverRegularAvailability_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) GetDriverJourneys(ctx context.Context, in *GetDriverJourneysRequest, opts ...grpc.CallOption) (*GetDriverJourneysResponse, error) {
out := new(GetDriverJourneysResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_GetDriverJourneys_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) GetDriverJourney(ctx context.Context, in *GetDriverJourneyRequest, opts ...grpc.CallOption) (*GetDriverJourneyResponse, error) {
out := new(GetDriverJourneyResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_GetDriverJourney_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) BookDriverJourney(ctx context.Context, in *BookDriverJourneyRequest, opts ...grpc.CallOption) (*BookDriverJourneyResponse, error) {
out := new(BookDriverJourneyResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_BookDriverJourney_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) GetSolidarityTransportBookings(ctx context.Context, in *GetSolidarityTransportBookingsRequest, opts ...grpc.CallOption) (*GetSolidarityTransportBookingsResponse, error) {
out := new(GetSolidarityTransportBookingsResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_GetSolidarityTransportBookings_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) GetSolidarityTransportBooking(ctx context.Context, in *GetSolidarityTransportBookingRequest, opts ...grpc.CallOption) (*GetSolidarityTransportBookingResponse, error) {
out := new(GetSolidarityTransportBookingResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_GetSolidarityTransportBooking_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *solidarityTransportClient) UpdateSolidarityTransportBookingStatus(ctx context.Context, in *UpdateSolidarityTransportBookingStatusRequest, opts ...grpc.CallOption) (*UpdateSolidarityTransportBookingStatusResponse, error) {
out := new(UpdateSolidarityTransportBookingStatusResponse)
err := c.cc.Invoke(ctx, SolidarityTransport_UpdateSolidarityTransportBookingStatus_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// SolidarityTransportServer is the server API for SolidarityTransport service.
// All implementations must embed UnimplementedSolidarityTransportServer
// for forward compatibility
type SolidarityTransportServer interface {
// Availabilities management
AddDriverRegularAvailability(context.Context, *AddDriverRegularAvailabilityRequest) (*AddDriverRegularAvailabilityResponse, error)
AddDriverRegularAvailabilities(context.Context, *AddDriverRegularAvailabilitiesRequest) (*AddDriverRegularAvailabilitiesResponse, error)
GetDriverRegularAvailabilities(context.Context, *GetDriverRegularAvailabilitiesRequest) (*GetDriverRegularAvailabilitiesResponse, error)
DeleteDriverRegularAvailability(context.Context, *DeleteDriverRegularAvailabilityRequest) (*DeleteDriverRegularAvailabilityResponse, error)
// Search / Journeys
GetDriverJourneys(context.Context, *GetDriverJourneysRequest) (*GetDriverJourneysResponse, error)
GetDriverJourney(context.Context, *GetDriverJourneyRequest) (*GetDriverJourneyResponse, error)
// Booking flows
BookDriverJourney(context.Context, *BookDriverJourneyRequest) (*BookDriverJourneyResponse, error)
GetSolidarityTransportBookings(context.Context, *GetSolidarityTransportBookingsRequest) (*GetSolidarityTransportBookingsResponse, error)
GetSolidarityTransportBooking(context.Context, *GetSolidarityTransportBookingRequest) (*GetSolidarityTransportBookingResponse, error)
UpdateSolidarityTransportBookingStatus(context.Context, *UpdateSolidarityTransportBookingStatusRequest) (*UpdateSolidarityTransportBookingStatusResponse, error)
mustEmbedUnimplementedSolidarityTransportServer()
}
// UnimplementedSolidarityTransportServer must be embedded to have forward compatible implementations.
type UnimplementedSolidarityTransportServer struct {
}
func (UnimplementedSolidarityTransportServer) AddDriverRegularAvailability(context.Context, *AddDriverRegularAvailabilityRequest) (*AddDriverRegularAvailabilityResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddDriverRegularAvailability not implemented")
}
func (UnimplementedSolidarityTransportServer) AddDriverRegularAvailabilities(context.Context, *AddDriverRegularAvailabilitiesRequest) (*AddDriverRegularAvailabilitiesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddDriverRegularAvailabilities not implemented")
}
func (UnimplementedSolidarityTransportServer) GetDriverRegularAvailabilities(context.Context, *GetDriverRegularAvailabilitiesRequest) (*GetDriverRegularAvailabilitiesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDriverRegularAvailabilities not implemented")
}
func (UnimplementedSolidarityTransportServer) DeleteDriverRegularAvailability(context.Context, *DeleteDriverRegularAvailabilityRequest) (*DeleteDriverRegularAvailabilityResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteDriverRegularAvailability not implemented")
}
func (UnimplementedSolidarityTransportServer) GetDriverJourneys(context.Context, *GetDriverJourneysRequest) (*GetDriverJourneysResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDriverJourneys not implemented")
}
func (UnimplementedSolidarityTransportServer) GetDriverJourney(context.Context, *GetDriverJourneyRequest) (*GetDriverJourneyResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDriverJourney not implemented")
}
func (UnimplementedSolidarityTransportServer) BookDriverJourney(context.Context, *BookDriverJourneyRequest) (*BookDriverJourneyResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method BookDriverJourney not implemented")
}
func (UnimplementedSolidarityTransportServer) GetSolidarityTransportBookings(context.Context, *GetSolidarityTransportBookingsRequest) (*GetSolidarityTransportBookingsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetSolidarityTransportBookings not implemented")
}
func (UnimplementedSolidarityTransportServer) GetSolidarityTransportBooking(context.Context, *GetSolidarityTransportBookingRequest) (*GetSolidarityTransportBookingResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetSolidarityTransportBooking not implemented")
}
func (UnimplementedSolidarityTransportServer) UpdateSolidarityTransportBookingStatus(context.Context, *UpdateSolidarityTransportBookingStatusRequest) (*UpdateSolidarityTransportBookingStatusResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateSolidarityTransportBookingStatus not implemented")
}
func (UnimplementedSolidarityTransportServer) mustEmbedUnimplementedSolidarityTransportServer() {}
// UnsafeSolidarityTransportServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to SolidarityTransportServer will
// result in compilation errors.
type UnsafeSolidarityTransportServer interface {
mustEmbedUnimplementedSolidarityTransportServer()
}
func RegisterSolidarityTransportServer(s grpc.ServiceRegistrar, srv SolidarityTransportServer) {
s.RegisterService(&SolidarityTransport_ServiceDesc, srv)
}
func _SolidarityTransport_AddDriverRegularAvailability_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddDriverRegularAvailabilityRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).AddDriverRegularAvailability(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_AddDriverRegularAvailability_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).AddDriverRegularAvailability(ctx, req.(*AddDriverRegularAvailabilityRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_AddDriverRegularAvailabilities_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddDriverRegularAvailabilitiesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).AddDriverRegularAvailabilities(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_AddDriverRegularAvailabilities_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).AddDriverRegularAvailabilities(ctx, req.(*AddDriverRegularAvailabilitiesRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_GetDriverRegularAvailabilities_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetDriverRegularAvailabilitiesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).GetDriverRegularAvailabilities(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_GetDriverRegularAvailabilities_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).GetDriverRegularAvailabilities(ctx, req.(*GetDriverRegularAvailabilitiesRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_DeleteDriverRegularAvailability_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteDriverRegularAvailabilityRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).DeleteDriverRegularAvailability(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_DeleteDriverRegularAvailability_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).DeleteDriverRegularAvailability(ctx, req.(*DeleteDriverRegularAvailabilityRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_GetDriverJourneys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetDriverJourneysRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).GetDriverJourneys(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_GetDriverJourneys_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).GetDriverJourneys(ctx, req.(*GetDriverJourneysRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_GetDriverJourney_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetDriverJourneyRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).GetDriverJourney(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_GetDriverJourney_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).GetDriverJourney(ctx, req.(*GetDriverJourneyRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_BookDriverJourney_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(BookDriverJourneyRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).BookDriverJourney(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_BookDriverJourney_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).BookDriverJourney(ctx, req.(*BookDriverJourneyRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_GetSolidarityTransportBookings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetSolidarityTransportBookingsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).GetSolidarityTransportBookings(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_GetSolidarityTransportBookings_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).GetSolidarityTransportBookings(ctx, req.(*GetSolidarityTransportBookingsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_GetSolidarityTransportBooking_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetSolidarityTransportBookingRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).GetSolidarityTransportBooking(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_GetSolidarityTransportBooking_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).GetSolidarityTransportBooking(ctx, req.(*GetSolidarityTransportBookingRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SolidarityTransport_UpdateSolidarityTransportBookingStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateSolidarityTransportBookingStatusRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SolidarityTransportServer).UpdateSolidarityTransportBookingStatus(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SolidarityTransport_UpdateSolidarityTransportBookingStatus_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SolidarityTransportServer).UpdateSolidarityTransportBookingStatus(ctx, req.(*UpdateSolidarityTransportBookingStatusRequest))
}
return interceptor(ctx, in, info, handler)
}
// SolidarityTransport_ServiceDesc is the grpc.ServiceDesc for SolidarityTransport service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var SolidarityTransport_ServiceDesc = grpc.ServiceDesc{
ServiceName: "SolidarityTransport",
HandlerType: (*SolidarityTransportServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "AddDriverRegularAvailability",
Handler: _SolidarityTransport_AddDriverRegularAvailability_Handler,
},
{
MethodName: "AddDriverRegularAvailabilities",
Handler: _SolidarityTransport_AddDriverRegularAvailabilities_Handler,
},
{
MethodName: "GetDriverRegularAvailabilities",
Handler: _SolidarityTransport_GetDriverRegularAvailabilities_Handler,
},
{
MethodName: "DeleteDriverRegularAvailability",
Handler: _SolidarityTransport_DeleteDriverRegularAvailability_Handler,
},
{
MethodName: "GetDriverJourneys",
Handler: _SolidarityTransport_GetDriverJourneys_Handler,
},
{
MethodName: "GetDriverJourney",
Handler: _SolidarityTransport_GetDriverJourney_Handler,
},
{
MethodName: "BookDriverJourney",
Handler: _SolidarityTransport_BookDriverJourney_Handler,
},
{
MethodName: "GetSolidarityTransportBookings",
Handler: _SolidarityTransport_GetSolidarityTransportBookings_Handler,
},
{
MethodName: "GetSolidarityTransportBooking",
Handler: _SolidarityTransport_GetSolidarityTransportBooking_Handler,
},
{
MethodName: "UpdateSolidarityTransportBookingStatus",
Handler: _SolidarityTransport_UpdateSolidarityTransportBookingStatus_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "solidarity-transport.proto",
}

View File

@ -0,0 +1,52 @@
syntax = "proto3";
option go_package = "git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen";
import "google/protobuf/timestamp.proto";
message GeoJsonFeature {
string serialized = 1;
}
message GeoJsonFeatureCollection {
string serialized = 1;
}
message DriverRegularAvailability {
string id = 1;
string driver_id = 2;
int32 day = 3;
string start_time = 4;
string end_time = 5;
GeoJsonFeature address = 6;
}
message SolidarityTransportDriverJourney{
string id = 1;
string driver_id = 2;
GeoJsonFeature passenger_pickup = 3;
GeoJsonFeature passenger_drop = 4;
int64 passenger_distance = 5;
GeoJsonFeature driver_departure = 6;
GeoJsonFeature driver_arrival = 7;
int64 driver_distance = 8;
int64 duration = 9;
optional string journey_polyline = 10;
google.protobuf.Timestamp passenger_pickup_date = 11;
optional google.protobuf.Timestamp driver_departure_date = 12;
optional SolidarityTransportPrice price = 13;
}
message SolidarityTransportPrice {
double amount = 1;
string currency = 2;
}
message SolidarityTransportBooking {
string id = 1;
string group_id = 2;
string driver_id = 3;
string passenger_id = 4;
string status = 5;
SolidarityTransportDriverJourney journey = 10;
}

View File

@ -0,0 +1,110 @@
syntax = "proto3";
option go_package = "git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen";
import "google/protobuf/timestamp.proto";
import "solidarity-transport-types.proto";
service SolidarityTransport {
//Availabilities management
rpc AddDriverRegularAvailability(AddDriverRegularAvailabilityRequest) returns (AddDriverRegularAvailabilityResponse) {}
rpc AddDriverRegularAvailabilities(AddDriverRegularAvailabilitiesRequest) returns (AddDriverRegularAvailabilitiesResponse) {}
rpc GetDriverRegularAvailabilities(GetDriverRegularAvailabilitiesRequest) returns (GetDriverRegularAvailabilitiesResponse) {}
rpc DeleteDriverRegularAvailability(DeleteDriverRegularAvailabilityRequest) returns (DeleteDriverRegularAvailabilityResponse) {}
// Search / Journeys
rpc GetDriverJourneys(GetDriverJourneysRequest) returns (GetDriverJourneysResponse) {}
rpc GetDriverJourney(GetDriverJourneyRequest) returns (GetDriverJourneyResponse) {}
// Booking flows
rpc BookDriverJourney(BookDriverJourneyRequest) returns (BookDriverJourneyResponse) {}
rpc GetSolidarityTransportBookings(GetSolidarityTransportBookingsRequest) returns (GetSolidarityTransportBookingsResponse) {}
rpc GetSolidarityTransportBooking(GetSolidarityTransportBookingRequest) returns (GetSolidarityTransportBookingResponse) {}
rpc UpdateSolidarityTransportBookingStatus(UpdateSolidarityTransportBookingStatusRequest) returns (UpdateSolidarityTransportBookingStatusResponse) {}
}
message AddDriverRegularAvailabilityRequest{
string driver_id = 1;
int32 day = 2;
string start_time = 3;
string end_time = 4;
GeoJsonFeature address = 5;
}
message AddDriverRegularAvailabilityResponse{}
message AddDriverRegularAvailabilitiesRequest{
repeated DriverRegularAvailability availabilities = 1;
}
message AddDriverRegularAvailabilitiesResponse{}
message GetDriverRegularAvailabilitiesRequest {
string driver_id = 1;
}
message GetDriverRegularAvailabilitiesResponse {
repeated DriverRegularAvailability results = 1;
}
message DeleteDriverRegularAvailabilityRequest {
string driver_id = 1;
string availability_id = 2;
}
message DeleteDriverRegularAvailabilityResponse {}
// Search / Journeys
message GetDriverJourneysRequest {
GeoJsonFeature departure = 1;
GeoJsonFeature arrival = 3;
google.protobuf.Timestamp departure_date = 5;
optional int64 time_delta = 6;
}
message GetDriverJourneysResponse {
repeated SolidarityTransportDriverJourney driver_journeys = 1;
}
message GetDriverJourneyRequest {
string driver_id = 1;
string journey_id = 2;
}
message GetDriverJourneyResponse {
SolidarityTransportDriverJourney driver_journey = 1;
}
message BookDriverJourneyRequest {
string passenger_id = 1;
string driver_id = 2;
string driver_journey_id = 3;
}
message BookDriverJourneyResponse {
}
message GetSolidarityTransportBookingsRequest {
google.protobuf.Timestamp start_date = 1;
google.protobuf.Timestamp end_date = 2;
}
message GetSolidarityTransportBookingsResponse {
repeated SolidarityTransportBooking bookings = 1;
}
message GetSolidarityTransportBookingRequest {
string id = 1;
}
message GetSolidarityTransportBookingResponse {
SolidarityTransportBooking booking = 1;
}
message UpdateSolidarityTransportBookingStatusRequest {
string booking_id = 1;
string new_status = 2;
}
message UpdateSolidarityTransportBookingStatusResponse {}

View File

@ -0,0 +1,74 @@
package server
import (
"context"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/transformers"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s SolidarityTransportServerImpl) AddDriverRegularAvailability(ctx context.Context, req *gen.AddDriverRegularAvailabilityRequest) (*gen.AddDriverRegularAvailabilityResponse, error) {
if err := s.Handler.AddRegularAvailability(req.DriverId, int(req.Day), req.StartTime, req.EndTime); err != nil {
return nil, status.Errorf(codes.Internal, "AddDriverRegularAvailability : %v", err)
}
return &gen.AddDriverRegularAvailabilityResponse{}, nil
}
func (s SolidarityTransportServerImpl) AddDriverRegularAvailabilities(ctx context.Context, req *gen.AddDriverRegularAvailabilitiesRequest) (*gen.AddDriverRegularAvailabilitiesResponse, error) {
log.Info().Msg("grpc call - AddDriverRegularAvailabilities")
availabilities := []*types.DriverRegularAvailability{}
for _, a := range req.Availabilities {
if a != nil {
log.Debug().Any("availability", a).Msg("New availability")
na := transformers.DriverRegularAvailabilityProtoToType(a)
availabilities = append(availabilities, na)
}
}
if err := s.Handler.AddDriverRegularAvailabilities(availabilities); err != nil {
log.Error().Err(err).Msg("AddDriverAvailabilities error")
return nil, status.Errorf(codes.Internal, "AddDriverRegularAvailabilities : %v", err)
}
return &gen.AddDriverRegularAvailabilitiesResponse{}, nil
}
func (s SolidarityTransportServerImpl) GetDriverRegularAvailabilities(ctx context.Context, req *gen.GetDriverRegularAvailabilitiesRequest) (*gen.GetDriverRegularAvailabilitiesResponse, error) {
log.Info().Str("driver", req.DriverId).Msg("grpc call - GetDriverRegularAvailabilities")
availabilities, err := s.Handler.GetDriverRegularAvailabilities(req.DriverId)
if err != nil {
log.Error().Err(err).Msg("GetDriverRegularAvailabilities error")
return nil, status.Errorf(codes.Internal, "GetDriverRegularAvailabilities : %v", err)
}
results := []*gen.DriverRegularAvailability{}
log.Debug().Any("availabilities", availabilities).Msg("retrieved availabilities")
for _, a := range availabilities {
if a != nil {
log.Debug().Any("availability", a).Msg("Availability")
protoavailability := transformers.DriverRegularAvailabilityTypeToProto(a)
results = append(results, protoavailability)
}
}
return &gen.GetDriverRegularAvailabilitiesResponse{
Results: results,
}, nil
}
func (s SolidarityTransportServerImpl) DeleteDriverRegularAvailability(ctx context.Context, req *gen.DeleteDriverRegularAvailabilityRequest) (*gen.DeleteDriverRegularAvailabilityResponse, error) {
driverid := req.DriverId
availabilityid := req.AvailabilityId
if err := s.Handler.DeleteDriverRegularAvailabilities(driverid, availabilityid); err != nil {
log.Error().Err(err).Msg("DeleteDriverRegularAvailability error")
return nil, status.Errorf(codes.Internal, "DeleteDriverRegularAvailability error : %v", err)
}
return &gen.DeleteDriverRegularAvailabilityResponse{}, nil
}

View File

@ -0,0 +1,76 @@
package server
import (
"context"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/transformers"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s SolidarityTransportServerImpl) BookDriverJourney(ctx context.Context, req *gen.BookDriverJourneyRequest) (*gen.BookDriverJourneyResponse, error) {
passengerId := req.PassengerId
driverId := req.DriverId
journeyId := req.DriverJourneyId
if err := s.Handler.BookDriverJourney(passengerId, driverId, journeyId); err != nil {
log.Error().Err(err).Msg("issue in BookDriverJourney handler")
return nil, status.Errorf(codes.Internal, "could not create booking : %v", err)
}
return &gen.BookDriverJourneyResponse{}, nil
}
func (s SolidarityTransportServerImpl) GetSolidarityTransportBookings(ctx context.Context, req *gen.GetSolidarityTransportBookingsRequest) (*gen.GetSolidarityTransportBookingsResponse, error) {
startdate := req.StartDate.AsTime()
enddate := req.EndDate.AsTime()
bookings, err := s.Handler.GetBookings(startdate, enddate)
if err != nil {
log.Error().Err(err).Msg("issue in GetBookings handler")
return nil, status.Errorf(codes.NotFound, "could not get bookings : %v", err)
}
protobookings := []*gen.SolidarityTransportBooking{}
for _, b := range bookings {
protobooking, _ := transformers.BookingTypeToProto(b)
protobookings = append(protobookings, protobooking)
}
return &gen.GetSolidarityTransportBookingsResponse{
Bookings: protobookings,
}, nil
}
func (s SolidarityTransportServerImpl) GetSolidarityTransportBooking(ctx context.Context, req *gen.GetSolidarityTransportBookingRequest) (*gen.GetSolidarityTransportBookingResponse, error) {
bookingid := req.Id
booking, err := s.Handler.GetBooking(bookingid)
if err != nil {
log.Error().Err(err).Msg("issue in GetBooking handler")
return nil, status.Errorf(codes.NotFound, "could not get booking : %v", err)
}
bookingproto, err := transformers.BookingTypeToProto(booking)
if err != nil {
log.Error().Err(err).Msg("issue in GetBooking handler")
return nil, status.Errorf(codes.NotFound, "transformer issue on booking : %v", err)
}
return &gen.GetSolidarityTransportBookingResponse{
Booking: bookingproto,
}, nil
}
func (s SolidarityTransportServerImpl) UpdateSolidarityTransportBookingStatus(ctx context.Context, req *gen.UpdateSolidarityTransportBookingStatusRequest) (*gen.UpdateSolidarityTransportBookingStatusResponse, error) {
bookingid := req.BookingId
newStatus := req.NewStatus
err := s.Handler.UpdateBookingStatus(bookingid, newStatus)
if err != nil {
log.Error().Err(err).Msg("issue in GetBooking handler")
return nil, status.Errorf(codes.NotFound, "transformer issue on booking : %v", err)
}
return &gen.UpdateSolidarityTransportBookingStatusResponse{}, nil
}

View File

@ -0,0 +1,67 @@
package server
import (
"context"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/transformers"
"github.com/paulmach/orb/geojson"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s SolidarityTransportServerImpl) GetDriverJourneys(ctx context.Context, req *gen.GetDriverJourneysRequest) (*gen.GetDriverJourneysResponse, error) {
departureDate := req.DepartureDate.AsTime()
departure, err := geojson.UnmarshalFeature([]byte(req.Departure.Serialized))
if err != nil {
return nil, status.Errorf(codes.Internal, "departure unmarshalling error: %v", err)
}
arrival, err := geojson.UnmarshalFeature([]byte(req.Arrival.Serialized))
if err != nil {
return nil, status.Errorf(codes.Internal, "arrival unmarhsalling error : %v", err)
}
driverJourneys, err := s.Handler.GetDriverJourneys(departure, arrival, departureDate)
if err != nil {
log.Error().Err(err).Msg("issue in GetDriverJourneys handler")
return nil, status.Errorf(codes.Internal, "could not get driver journeys : %v", err)
}
results := []*gen.SolidarityTransportDriverJourney{}
for _, j := range driverJourneys {
// transformer
dj, err := transformers.DriverJourneyTypeToProto(j)
if err != nil {
log.Error().Err(err).Msg("issue while converting DriverJourney type to protobuf")
continue
// return nil, status.Errorf(codes.Internal, "could not get driver journeys : %v", err)
}
results = append(results, dj)
}
return &gen.GetDriverJourneysResponse{
DriverJourneys: results,
}, nil
}
func (s SolidarityTransportServerImpl) GetDriverJourney(ctx context.Context, req *gen.GetDriverJourneyRequest) (*gen.GetDriverJourneyResponse, error) {
driverid := req.DriverId
journeyid := req.JourneyId
journey, err := s.Handler.GetDriverJourney(driverid, journeyid)
if err != nil {
return nil, status.Errorf(codes.NotFound, "could not get driver journey : %v", err)
}
protojourney, err := transformers.DriverJourneyTypeToProto(journey)
if err != nil {
log.Error().Err(err).Msg("transformation error")
return nil, status.Errorf(codes.NotFound, "transformation error : %v", err)
}
return &gen.GetDriverJourneyResponse{
DriverJourney: protojourney,
}, nil
}

View File

@ -0,0 +1,50 @@
package server
import (
"fmt"
"net"
"git.coopgo.io/coopgo-platform/solidarity-transport/handler"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
type SolidarityTransportServerImpl struct {
Handler *handler.Handler
gen.UnimplementedSolidarityTransportServer
}
func NewSolidarityTransportServer(handler *handler.Handler) *SolidarityTransportServerImpl {
return &SolidarityTransportServerImpl{
Handler: handler,
}
}
func Run(done chan error, cfg *viper.Viper, handler *handler.Handler) {
var (
dev_env = cfg.GetBool("dev_env")
address = ":" + cfg.GetString("services.grpc.port")
)
server := grpc.NewServer()
gen.RegisterSolidarityTransportServer(server, NewSolidarityTransportServer(handler))
l, err := net.Listen("tcp", address)
if err != nil {
log.Fatal().Err(err).Msg("could not register solidarity transport grpc server")
return
}
if dev_env {
reflection.Register(server)
}
if err := server.Serve(l); err != nil {
fmt.Println("gRPC service ended")
done <- err
}
}

View File

@ -0,0 +1,34 @@
package transformers
import (
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/paulmach/orb/geojson"
)
func DriverRegularAvailabilityProtoToType(a *gen.DriverRegularAvailability) *types.DriverRegularAvailability {
address, _ := geojson.UnmarshalFeature([]byte(a.Address.Serialized))
return &types.DriverRegularAvailability{
ID: a.Id,
DriverId: a.DriverId,
Day: int(a.Day),
StartTime: a.StartTime,
EndTime: a.EndTime,
Address: address,
}
}
func DriverRegularAvailabilityTypeToProto(a *types.DriverRegularAvailability) *gen.DriverRegularAvailability {
address := []byte("")
if a.Address != nil {
address, _ = a.Address.MarshalJSON()
}
return &gen.DriverRegularAvailability{
Id: a.ID,
Day: int32(a.Day),
DriverId: a.DriverId,
StartTime: a.StartTime,
EndTime: a.EndTime,
Address: &gen.GeoJsonFeature{Serialized: string(address)},
}
}

View File

@ -0,0 +1,36 @@
package transformers
import (
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
)
func BookingTypeToProto(booking *types.Booking) (*gen.SolidarityTransportBooking, error) {
journey, err := DriverJourneyTypeToProto(booking.Journey)
if err != nil {
return nil, err
}
return &gen.SolidarityTransportBooking{
Id: booking.Id,
GroupId: booking.GroupId,
DriverId: booking.DriverId,
PassengerId: booking.PassengerId,
Status: booking.Status,
Journey: journey,
}, nil
}
func BookingProtoToType(booking *gen.SolidarityTransportBooking) (*types.Booking, error) {
journey, err := DriverJourneyProtoToType(booking.Journey)
if err != nil {
return nil, err
}
return &types.Booking{
Id: booking.Id,
GroupId: booking.GroupId,
DriverId: booking.DriverId,
PassengerId: booking.PassengerId,
Status: booking.Status,
Journey: journey,
}, nil
}

View File

@ -0,0 +1,24 @@
package transformers
import (
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"github.com/paulmach/orb/geojson"
)
func GeoJsonToProto(feature *geojson.Feature) (*gen.GeoJsonFeature, error) {
serialized, err := feature.MarshalJSON()
if err != nil {
return nil, err
}
return &gen.GeoJsonFeature{
Serialized: string(serialized),
}, nil
}
func ProtoToGeoJson(feature *gen.GeoJsonFeature) (*geojson.Feature, error) {
gj, err := geojson.UnmarshalFeature([]byte(feature.Serialized))
if err != nil {
return nil, err
}
return gj, err
}

View File

@ -0,0 +1,100 @@
package transformers
import (
"time"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/paulmach/orb/geojson"
"google.golang.org/protobuf/types/known/timestamppb"
)
func DriverJourneyTypeToProto(j *types.DriverJourney) (*gen.SolidarityTransportDriverJourney, error) {
passengerPickup, err := j.PassengerPickup.MarshalJSON()
if err != nil {
return nil, err
}
passengerDrop, err := j.PassengerDrop.MarshalJSON()
if err != nil {
return nil, err
}
driverDeparture, err := j.DriverDeparture.MarshalJSON()
if err != nil {
return nil, err
}
driverArrival, err := j.DriverArrival.MarshalJSON()
if err != nil {
return nil, err
}
return &gen.SolidarityTransportDriverJourney{
Id: j.Id,
DriverId: j.DriverId,
PassengerPickup: &gen.GeoJsonFeature{
Serialized: string(passengerPickup),
},
PassengerDrop: &gen.GeoJsonFeature{
Serialized: string(passengerDrop),
},
PassengerDistance: j.PassengerDistance,
DriverDeparture: &gen.GeoJsonFeature{
Serialized: string(driverDeparture),
},
DriverArrival: &gen.GeoJsonFeature{
Serialized: string(driverArrival),
},
DriverDistance: j.DriverDistance,
Duration: int64(j.Duration.Seconds()),
JourneyPolyline: &j.JourneyPolyline,
DriverDepartureDate: timestamppb.New(j.DriverDepartureDate),
PassengerPickupDate: timestamppb.New(j.PassengerPickupDate),
Price: &gen.SolidarityTransportPrice{
Amount: 0,
Currency: "EUR",
},
}, nil
}
func DriverJourneyProtoToType(j *gen.SolidarityTransportDriverJourney) (*types.DriverJourney, error) {
passengerPickup, err := geojson.UnmarshalFeature([]byte(j.PassengerPickup.Serialized))
if err != nil {
return nil, err
}
passengerDrop, err := geojson.UnmarshalFeature([]byte(j.PassengerDrop.Serialized))
if err != nil {
return nil, err
}
driverDeparture, err := geojson.UnmarshalFeature([]byte(j.DriverDeparture.Serialized))
if err != nil {
return nil, err
}
driverArrival, err := geojson.UnmarshalFeature([]byte(j.DriverArrival.Serialized))
if err != nil {
return nil, err
}
return &types.DriverJourney{
Id: j.Id,
DriverId: j.DriverId,
PassengerPickup: passengerPickup,
PassengerDrop: passengerDrop,
PassengerDistance: j.PassengerDistance,
DriverDeparture: driverDeparture,
DriverArrival: driverArrival,
DriverDistance: j.DriverDistance,
Duration: time.Duration(j.Duration) * time.Second,
JourneyPolyline: *j.JourneyPolyline,
DriverDepartureDate: j.DriverDepartureDate.AsTime(),
PassengerPickupDate: j.PassengerPickupDate.AsTime(),
Price: types.SolidarityTransportPrice{
Amount: j.Price.Amount,
Currency: j.Price.Currency,
},
}, nil
}

152
storage/memory.go Normal file
View File

@ -0,0 +1,152 @@
package storage
import (
"errors"
"strings"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/google/uuid"
"github.com/spf13/viper"
)
type MemoryStorage struct {
DriverRegularAvailabilities map[string]*types.DriverRegularAvailability
DriverJourneys map[string]*types.DriverJourney
Bookings map[string]*types.Booking
}
func NewMemoryStorage(cfg *viper.Viper) (MemoryStorage, error) {
return MemoryStorage{
DriverRegularAvailabilities: map[string]*types.DriverRegularAvailability{},
}, nil
}
func (s MemoryStorage) CreateDriverRegularAvailability(availability types.DriverRegularAvailability) error {
if availability.ID == "" {
availability.ID = uuid.NewString()
}
if s.DriverRegularAvailabilities[availability.ID] != nil {
return errors.New("availability already exists")
}
s.DriverRegularAvailabilities[availability.ID] = &availability
return nil
}
func (s MemoryStorage) CreateDriverRegularAvailabilities(availabilities []*types.DriverRegularAvailability) error {
for _, availability := range availabilities {
if availability != nil {
if err := s.CreateDriverRegularAvailability(*availability); err != nil {
return err
}
}
}
return nil
}
func (s MemoryStorage) DeleteDriverRegularAvailability(driverid string, availabilityid string) error {
if s.DriverRegularAvailabilities[availabilityid] == nil {
return errors.New("availability doesn't exist")
}
if s.DriverRegularAvailabilities[availabilityid].DriverId != driverid {
return errors.New("unallowed to delete this availability : driver mismatch")
}
s.DriverRegularAvailabilities[availabilityid] = nil
return nil
}
func (s MemoryStorage) GetDriverRegularAvailability(driverid string, availabilityid string) (*types.DriverRegularAvailability, error) {
if s.DriverRegularAvailabilities[availabilityid] == nil {
return nil, errors.New("availability doesn't exist")
}
if s.DriverRegularAvailabilities[availabilityid].DriverId != driverid {
return nil, errors.New("unallowed to get this availability : driver mismatch")
}
return s.DriverRegularAvailabilities[availabilityid], nil
}
func (s MemoryStorage) GetDriverRegularAvailabilities(driverid string) ([]*types.DriverRegularAvailability, error) {
result := []*types.DriverRegularAvailability{}
for _, a := range s.DriverRegularAvailabilities {
if a.DriverId == driverid {
result = append(result, a)
}
}
return result, nil
}
func (s MemoryStorage) GetRegularAvailabilities(day int, timeInDay string) ([]*types.DriverRegularAvailability, error) {
results := []*types.DriverRegularAvailability{}
for _, a := range s.DriverRegularAvailabilities {
if a.Day == day && strings.Compare(a.StartTime, timeInDay) <= 0 && strings.Compare(a.EndTime, timeInDay) >= 0 {
results = append(results, a)
}
}
return results, nil
}
func (s MemoryStorage) PushDriverJourneys(driverjourneys []*types.DriverJourney) error {
for _, j := range driverjourneys {
s.DriverJourneys[j.Id] = j
}
return nil
}
func (s MemoryStorage) GetDriverJourney(id string) (res *types.DriverJourney, err error) {
res = s.DriverJourneys[id]
if res == nil {
err = errors.New("not found")
}
return
}
func (s MemoryStorage) CreateBooking(booking types.Booking) error {
if booking.Id == "" {
booking.Id = uuid.NewString()
}
if s.Bookings[booking.Id] != nil {
return errors.New("booking already exists")
}
s.Bookings[booking.Id] = &booking
return nil
}
func (s MemoryStorage) GetAllBookings() ([]*types.Booking, error) {
res := []*types.Booking{}
for _, b := range s.Bookings {
res = append(res, b)
}
return res, nil
}
func (s MemoryStorage) GetBooking(id string) (res *types.Booking, err error) {
res = s.Bookings[id]
if res == nil {
err = errors.New("not found")
}
return
}
func (s MemoryStorage) UpdateBookingStatus(bookingid string, newStatus string) error {
b := s.Bookings[bookingid]
if b == nil {
return errors.New("booking doesn't exist")
}
b.Status = newStatus
return nil
}

214
storage/mongodb.go Normal file
View File

@ -0,0 +1,214 @@
package storage
import (
"context"
"fmt"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
type MongoDBCollections struct {
DriversRegularAvailabilities *mongo.Collection
Bookings *mongo.Collection
DriverJourneys *mongo.Collection
}
type MongoDBStorage struct {
Client *mongo.Client
DbName string
Collections MongoDBCollections
}
func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
var (
mongodb_uri = cfg.GetString("storage.db.mongodb.uri")
mongodb_host = cfg.GetString("storage.db.mongodb.host")
mongodb_port = cfg.GetString("storage.db.mongodb.port")
mongodb_dbname = cfg.GetString("storage.db.mongodb.db_name")
mongodb_drivers_regular_availabilities = cfg.GetString("storage.db.mongodb.collections.drivers_regular_availabilities")
mongodb_bookings = cfg.GetString("storage.db.mongodb.collections.bookings")
mongodb_driver_journeys = cfg.GetString("storage.db.mongodb.collections.driver_journeys")
)
if mongodb_uri == "" {
mongodb_uri = fmt.Sprintf("mongodb://%s:%s/%s", mongodb_host, mongodb_port, mongodb_dbname)
}
client, err := mongo.Connect(options.Client().ApplyURI(mongodb_uri))
if err != nil {
return MongoDBStorage{}, err
}
log.Info().Str("regular availabilities", mongodb_drivers_regular_availabilities).Str("bookings", mongodb_bookings).Msg("mongodb collections")
return MongoDBStorage{
Client: client,
DbName: mongodb_dbname,
Collections: MongoDBCollections{
DriversRegularAvailabilities: client.Database(mongodb_dbname).Collection(mongodb_drivers_regular_availabilities),
Bookings: client.Database(mongodb_dbname).Collection(mongodb_bookings),
DriverJourneys: client.Database(mongodb_dbname).Collection(mongodb_driver_journeys),
},
}, nil
}
func (s MongoDBStorage) CreateDriverRegularAvailability(availability types.DriverRegularAvailability) error {
if availability.ID == "" {
availability.ID = uuid.NewString()
}
if _, err := s.Collections.DriversRegularAvailabilities.InsertOne(context.Background(), availability); err != nil {
log.Error().Err(err).Msg("CreateDriverAvailability error")
return err
}
return nil
}
func (s MongoDBStorage) CreateDriverRegularAvailabilities(availabilities []*types.DriverRegularAvailability) error {
for _, availability := range availabilities {
if availability.ID == "" {
availability.ID = uuid.NewString()
}
}
if _, err := s.Collections.DriversRegularAvailabilities.InsertMany(context.Background(), availabilities); err != nil {
log.Error().Err(err).Msg("CreateDriverAvailabilities error")
return err
}
return nil
}
func (s MongoDBStorage) DeleteDriverRegularAvailability(driverid string, availabilityid string) error {
if _, err := s.Collections.DriversRegularAvailabilities.DeleteOne(context.Background(), bson.M{"_id": availabilityid, "driver_id": driverid}); err != nil {
log.Error().Err(err).Msg("DeleteDriverRegularAvailability error")
return err
}
return nil
}
func (s MongoDBStorage) GetDriverRegularAvailability(driverid string, availabilityid string) (*types.DriverRegularAvailability, error) {
var result types.DriverRegularAvailability
if err := s.Collections.DriversRegularAvailabilities.FindOne(context.Background(), bson.M{"_id": availabilityid, "driver_id": driverid}).Decode(&result); err != nil {
log.Error().Err(err).Msg("GetDriverRegularAvailability - error")
return nil, err
}
return &result, nil
}
func (s MongoDBStorage) GetDriverRegularAvailabilities(driverid string) ([]*types.DriverRegularAvailability, error) {
result := []*types.DriverRegularAvailability{}
cur, err := s.Collections.DriversRegularAvailabilities.Find(context.Background(), bson.M{"driver_id": driverid})
if err != nil {
log.Error().Err(err).Msg("GetDriverAvailabilities DB find - error")
return nil, err
}
if err = cur.All(context.Background(), &result); err != nil {
log.Error().Err(err).Msg("GetDriverAvailabilities cursor decoding - error")
return nil, err
}
return result, nil
}
func (s MongoDBStorage) GetRegularAvailabilities(day int, timeInDay string) ([]*types.DriverRegularAvailability, error) {
result := []*types.DriverRegularAvailability{}
cur, err := s.Collections.DriversRegularAvailabilities.Find(context.Background(),
bson.M{
"day": day,
"start_time": bson.M{"$lt": timeInDay},
"end_time": bson.M{"$gt": timeInDay},
})
if err != nil {
log.Error().Err(err).Msg("GetDriverAvailabilities DB find - error")
return nil, err
}
if err = cur.All(context.Background(), &result); err != nil {
log.Error().Err(err).Msg("GetDriverAvailabilities cursor decoding - error")
return nil, err
}
return result, nil
}
func (s MongoDBStorage) PushDriverJourneys(driverjourneys []*types.DriverJourney) error {
for _, journey := range driverjourneys {
if journey.Id == "" {
journey.Id = uuid.NewString()
}
}
if _, err := s.Collections.DriverJourneys.InsertMany(context.Background(), driverjourneys); err != nil {
log.Error().Err(err).Msg("PushDriverJourneys error")
return err
}
return nil
}
func (s MongoDBStorage) GetDriverJourney(id string) (*types.DriverJourney, error) {
var res types.DriverJourney
err := s.Collections.DriverJourneys.FindOne(context.Background(), bson.M{"_id": id}).Decode(&res)
if err != nil {
return nil, err
}
return &res, nil
}
func (s MongoDBStorage) CreateBooking(booking types.Booking) error {
if booking.Id == "" {
booking.Id = uuid.NewString()
}
if _, err := s.Collections.Bookings.InsertOne(context.Background(), booking); err != nil {
log.Error().Err(err).Msg("CreateBooking error")
return err
}
return nil
}
func (s MongoDBStorage) GetAllBookings() ([]*types.Booking, error) {
res := []*types.Booking{}
cur, err := s.Collections.Bookings.Find(context.Background(), bson.M{})
if err != nil {
return nil, err
}
err = cur.All(context.Background(), &res)
return res, err
}
func (s MongoDBStorage) GetBooking(id string) (*types.Booking, error) {
var res types.Booking
err := s.Collections.Bookings.FindOne(context.Background(), bson.M{"_id": id}).Decode(&res)
if err != nil {
return nil, err
}
return &res, nil
}
func (s MongoDBStorage) UpdateBookingStatus(bookingid string, newStatus string) error {
// filter := bson.M{"_id": bookingid}
replacement := bson.M{"$set": bson.M{"status": newStatus}}
if _, err := s.Collections.Bookings.UpdateByID(context.Background(), bookingid, replacement); err != nil {
return err
}
return nil
}

40
storage/storage.go Normal file
View File

@ -0,0 +1,40 @@
package storage
import (
"fmt"
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
"github.com/spf13/viper"
)
type Storage interface {
CreateDriverRegularAvailability(types.DriverRegularAvailability) error
CreateDriverRegularAvailabilities([]*types.DriverRegularAvailability) error
DeleteDriverRegularAvailability(driverid string, availabilityid string) error
GetDriverRegularAvailability(driverid string, availabilityid string) (*types.DriverRegularAvailability, error)
GetDriverRegularAvailabilities(driverid string) ([]*types.DriverRegularAvailability, error)
GetRegularAvailabilities(day int, timeInDay string) ([]*types.DriverRegularAvailability, error)
PushDriverJourneys([]*types.DriverJourney) error
GetDriverJourney(id string) (*types.DriverJourney, error)
CreateBooking(types.Booking) error
GetAllBookings() ([]*types.Booking, error)
GetBooking(id string) (*types.Booking, error)
UpdateBookingStatus(bookingid string, newStatus string) error
}
func NewStorage(cfg *viper.Viper) (Storage, error) {
storage_type := cfg.GetString("storage.db.type")
switch storage_type {
case "mongodb":
return NewMongoDBStorage(cfg)
case "memory":
return NewMemoryStorage(cfg)
default:
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
}
}

12
types/availabilities.go Normal file
View File

@ -0,0 +1,12 @@
package types
import geojson "github.com/paulmach/orb/geojson"
type DriverRegularAvailability struct {
ID string `json:"id" bson:"_id"`
DriverId string `json:"driver_id" bson:"driver_id"`
Day int `json:"day" bson:"day"`
StartTime string `json:"start_time" bson:"start_time"`
EndTime string `json:"end_time" bson:"end_time"`
Address *geojson.Feature `json:"address" bson:"address"`
}

11
types/booking.go Normal file
View File

@ -0,0 +1,11 @@
package types
type Booking struct {
Id string `json:"id" bson:"_id"`
GroupId string `json:"group_id" bson:"group_id"`
DriverId string `json:"driver_id" bson:"driver_id"`
PassengerId string `json:"passenger_id" bson:"passenger_id"`
Status string `json:"status" bson:"status"`
Journey *DriverJourney `json:"journey,omitempty" bson:"journey,omitempty"`
}

36
types/journeys.go Normal file
View File

@ -0,0 +1,36 @@
package types
import (
"time"
geojson "github.com/paulmach/orb/geojson"
)
type SolidarityTransportPrice struct {
Amount float64
Currency string
}
type DriverJourney struct {
Id string `json:"id" bson:"_id"`
DriverId string `json:"driver_id" bson:"driver_id"`
PassengerPickup *geojson.Feature `json:"passenger_pickup" bson:"passenger_pickup"`
PassengerDrop *geojson.Feature `json:"passenger_drop" bson:"passenger_drop"`
PassengerDistance int64 `json:"passenger_distance" bson:"passenger_distance"`
DriverDeparture *geojson.Feature `json:"driver_departure" bson:"driver_departure"`
DriverArrival *geojson.Feature `json:"driver_arrival" bson:"driver_arrival"`
DriverDistance int64 `json:"driver_distance" bson:"driver_distance"`
Duration time.Duration
JourneyPolyline string `json:"journey_polyline" bson:"journey_polyline"`
PassengerPickupDate time.Time `json:"passenger_pickup_date" bson:"passenger_pickup_date"`
DriverDepartureDate time.Time `json:"driver_departure_date" bson:"driver_departure_date"`
Price SolidarityTransportPrice
}
type PassengerTrip struct {
Id string `json:"id" bson:"_id"`
PassengerId string `json:"passenger_id" bson:"passenger_id"`
PassengerPickup *geojson.Feature `json:"passenger_pickup" bson:"passenger_pickup"`
PassengerDrop *geojson.Feature `json:"passenger_drop" bson:"passenger_drop"`
PassengerPickupDate time.Time `json:"passenger_pickup_date" bson:"passenger_pickup_date"`
}