Add PostgreSQL database option and more booking flow functionalities

This commit is contained in:
2023-05-08 01:29:59 +02:00
parent d8346a20be
commit e2e6759dc0
40 changed files with 1594 additions and 907 deletions

View File

@@ -3,13 +3,21 @@ package ocss
import (
"bytes"
"encoding/json"
"fmt"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
type BookingStatus int64
const (
BookingWaitingConfirmation BookingStatus = iota
BookingInitiated BookingStatus = iota
// BookingWaitingConfirmation
BookingWaitingDriverConfirmation
BookingWaitingPassengerConfirmation
BookingConfirmed
BookingCancelled
BookingCompletedPendingValidation
@@ -17,19 +25,25 @@ const (
)
var bookingStatustoID = map[string]BookingStatus{
"WAITING_CONFIRMATION": BookingWaitingConfirmation,
"CONFIRMED": BookingConfirmed,
"CANCELLED": BookingCancelled,
"COMPLETED_PENDING_VALIDATION": BookingCompletedPendingValidation,
"VALIDATED": BookingValidated,
"INITIATED": BookingInitiated,
// "WAITING_CONFIRMATION": BookingWaitingConfirmation,
"WAITING_DRIVER_CONFIRMATION": BookingWaitingDriverConfirmation,
"WAITING_PASSENGER_CONFIRMATION": BookingWaitingPassengerConfirmation,
"CONFIRMED": BookingConfirmed,
"CANCELLED": BookingCancelled,
"COMPLETED_PENDING_VALIDATION": BookingCompletedPendingValidation,
"VALIDATED": BookingValidated,
}
var bookingStatustoString = map[BookingStatus]string{
BookingWaitingConfirmation: "WAITING_CONFIRMATION",
BookingConfirmed: "CONFIRMED",
BookingCancelled: "CANCELLED",
BookingCompletedPendingValidation: "COMPLETED_PENDING_VALIDATION",
BookingValidated: "VALIDATED",
BookingInitiated: "INITIATED",
// BookingWaitingConfirmation: "WAITING_CONFIRMATION",
BookingWaitingDriverConfirmation: "WAITING_DRIVER_CONFIRMATION",
BookingWaitingPassengerConfirmation: "WAITING_PASSENGER_CONFIRMATION",
BookingConfirmed: "CONFIRMED",
BookingCancelled: "CANCELLED",
BookingCompletedPendingValidation: "COMPLETED_PENDING_VALIDATION",
BookingValidated: "VALIDATED",
}
func (s BookingStatus) MarshalJSON() ([]byte, error) {
@@ -39,34 +53,60 @@ func (s BookingStatus) MarshalJSON() ([]byte, error) {
return buffer.Bytes(), nil
}
func (s BookingStatus) MarshalBSONValue() (bsontype.Type, []byte, error) {
return bson.MarshalValue(bookingStatustoString[s])
}
func (bs *BookingStatus) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*bs = bookingStatustoID[j]
return nil
}
func (bs *BookingStatus) UnmarshalBSONValue(t bsontype.Type, b []byte) error {
if t == bsontype.Null || len(b) == 0 {
return nil
}
j, _, ok := bsoncore.ReadString(b)
if !ok {
return fmt.Errorf("cannot parse status")
}
*bs = bookingStatustoID[j]
return nil
}
func (bs *BookingStatus) String() string {
if bs == nil {
return ""
}
return bookingStatustoString[*bs]
}
func BookingStatusFromString(bs string) BookingStatus {
return bookingStatustoID[bs]
}
type Booking struct {
ID string `json:"id",bson:"_id"` // TODO check uuidv4
ID string `json:"id" bson:"_id"`
Driver User `json:"driver"`
Passenger User `json:"passenger"`
PassengerPickupDate JSONTime `json:"passengerPickupDate"`
PassengerPickupLat float64 `json:"passengerPickupLat"`
PassengerPickupLng float64 `json:"passengerPickupLng"`
PassengerDropLat float64 `json:"passengerDropLat"`
PassengerDropLng float64 `json:"passengerDropLng"`
PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty"`
PassengerDropAddress *string `json:"passengerDropAddress,omitempty"`
PassengerPickupDate OCSSTime `json:"passengerPickupDate" bson:"passengerPickupDate"`
PassengerPickupLat float64 `json:"passengerPickupLat" bson:"passengerPickupLat"`
PassengerPickupLng float64 `json:"passengerPickupLng" bson:"passengerPickupLng"`
PassengerDropLat float64 `json:"passengerDropLat" bson:"passengerDropLat"`
PassengerDropLng float64 `json:"passengerDropLng" bson:"passengerDropLng"`
PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty" bson:"passengerPickupAddress,omitempty"`
PassengerDropAddress *string `json:"passengerDropAddress,omitempty" bson:"passengerDropAddress,omitempty"`
Status BookingStatus `json:"status"`
Distance *int64 `json:"distance,omitempty"`
Duration *time.Duration `json:"duration,omitempty"`
WebUrl *string `json:"webUrl,omitempty"`
Distance *int64 `json:"distance,omitempty" bson:"distance,omitempty"`
Duration *time.Duration `json:"duration,omitempty" bson:"duration,omitempty"`
WebUrl *string `json:"webUrl,omitempty" bson:"webUrl,omitempty"`
Price Price `json:"price"`
Car *Car `json:"car,omitempty"`
DriverJourneyID string `json:"driverJourneyId"`
PassengerJourneyID string `json:"passengerJourneyId"`
Car *Car `json:"car,omitempty" bson:"car,omitempty"`
DriverJourneyID string `json:"driverJourneyId" bson:"driverJourneyId"`
PassengerJourneyID string `json:"passengerJourneyId" bson:"passengerJourneyId"`
}

View File

@@ -4,6 +4,9 @@ import (
"bytes"
"encoding/json"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsontype"
)
type CarpoolBookingStatus int64
@@ -39,6 +42,10 @@ func (s CarpoolBookingStatus) MarshalJSON() ([]byte, error) {
return buffer.Bytes(), nil
}
func (s CarpoolBookingStatus) MarshalBSONValue() (bsontype.Type, []byte, error) {
return bson.MarshalValue(carpoolBookingStatustoString[s])
}
func (bs *CarpoolBookingStatus) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
@@ -50,6 +57,17 @@ func (bs *CarpoolBookingStatus) UnmarshalJSON(b []byte) error {
return nil
}
func (bs *CarpoolBookingStatus) UnmarshalBSON(t bsontype.Type, b []byte) error {
var j string
err := bson.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*bs = carpoolBookingStatustoID[j]
return nil
}
type CarpoolBookingEventData struct {
CarpoolBooking
DriverCarpoolBooking
@@ -57,24 +75,24 @@ type CarpoolBookingEventData struct {
}
type CarpoolBookingEvent struct {
ID string `json:"id"` // TODO validate UUID
ID string `json:"id"`
IDToken string `json:"idToken"`
Data CarpoolBookingEventData `json:"data"`
}
type CarpoolBooking struct {
ID string `json:"id"`
PassengerPickupDate time.Time `json:"passengerPickupDate"`
PassengerPickupLat float64 `json:"passengerPickupLat"`
PassengerPickupLng float64 `json:"passengerPickupLng"`
PassengerDropLat float64 `json:"passengerDropLat"`
PassengerDropLng float64 `json:"passengerDropLng"`
PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty"`
PassengerDropAddress *string `json:"passengerDropAddress,omitempty"`
ID string `json:"id" bson:"_id"`
PassengerPickupDate time.Time `json:"passengerPickupDate" bson:"passengerPickupDate"`
PassengerPickupLat float64 `json:"passengerPickupLat" bson:"passengerPickupLat"`
PassengerPickupLng float64 `json:"passengerPickupLng" bson:"passengerPickupLng"`
PassengerDropLat float64 `json:"passengerDropLat" bson:"passengerDropLat"`
PassengerDropLng float64 `json:"passengerDropLng" bson:"passengerDropLng"`
PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty" bson:"passengerPickupAddress,omitempty"`
PassengerDropAddress *string `json:"passengerDropAddress,omitempty" bson:"passengerDropAddress,omitempty"`
Status CarpoolBookingStatus `json:"status"`
Distance *int64 `json:"distance,omitempty"`
Duration *time.Duration `json:"duration,omitempty"`
WebUrl string `json:"webUrl"`
Distance *int64 `json:"distance,omitempty" bson:"distance,omitempty"`
Duration *time.Duration `json:"duration,omitempty" bson:"duration,omitempty"`
WebUrl string `json:"webUrl" bson:"webUrl"`
}
type PassengerCarpoolBooking struct {
@@ -84,5 +102,5 @@ type PassengerCarpoolBooking struct {
type DriverCarpoolBooking struct {
Driver User `json:"driver"`
Price Price `json:"price"`
Car *Car `json:"car,omitempty"`
Car *Car `json:"car,omitempty" bson:"car,omitempty"`
}

View File

@@ -1,6 +1,6 @@
package ocss
type Car struct {
Model *string `json:"model,omitempty"`
Brand *string `json:"brand,omitempty"`
Model *string `json:"model,omitempty" bson:"model,omitempty"`
Brand *string `json:"brand,omitempty" bson:"brand,omitempty"`
}

View File

@@ -2,7 +2,15 @@ package ocss
import "errors"
type Client struct{}
type Client struct {
BaseURL string
}
func NewClient(baseUrl string) *Client {
return &Client{
BaseURL: baseUrl,
}
}
func (c Client) GetDriverJourneys() ([]DriverJourney, error) {
return nil, errors.New("not implemented")

View File

@@ -6,3 +6,8 @@ require (
github.com/gorilla/schema v1.2.0
golang.org/x/crypto v0.7.0
)
require (
github.com/paulmach/orb v0.9.0 // indirect
go.mongodb.org/mongo-driver v1.11.1 // indirect
)

View File

@@ -1,4 +1,74 @@
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/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/snappy v0.0.1/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/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
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/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
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/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/paulmach/orb v0.9.0 h1:MwA1DqOKtvCgm7u9RZ/pnYejTeDJPnr0+0oFajBbJqk=
github.com/paulmach/orb v0.9.0/go.mod h1:SudmOk85SXtmXAB3sLGyJ6tZy/8pdfrV0o6ef98Xc30=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
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/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.mongodb.org/mongo-driver v1.11.1 h1:QP0znIRTuL0jf1oBQoAoM0C6ZJfBK4kx0Uumtv1A7w8=
go.mongodb.org/mongo-driver v1.11.1/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8=
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-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
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/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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
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/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/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
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/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/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/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
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/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -1,11 +1,5 @@
package ocss
import (
"encoding/json"
"fmt"
"time"
)
type JourneyScheduleType int64
const (
@@ -24,54 +18,21 @@ func (t JourneyScheduleType) MarshalJSON() ([]byte, error) {
return []byte(types[t]), nil
}
type JSONTime time.Time
func (t JSONTime) MarshalJSON() ([]byte, error) {
//do your serializing here
stamp := fmt.Sprintf("%v", time.Time(t).Unix())
return []byte(stamp), nil
}
func (t *JSONTime) UnmarshalJSON(b []byte) error {
var timestamp int64
err := json.Unmarshal(b, &timestamp)
if err != nil {
return err
}
parsed := time.Unix(timestamp, 0)
if err != nil {
return err
}
jsontime := JSONTime(parsed)
*t = jsontime
return nil
}
func (t *JSONTime) ToTime() *time.Time {
if t == nil {
return nil
}
time := time.Time(*t)
return &time
}
type JourneySchedule struct {
ID *string `json:"id,omitempty"`
PassengerPickupDate JSONTime `json:"passengerPickupDate"`
PassengerDepartureDate *JSONTime `json:"passengerDepartureDate,omitempty"`
DriverDepartureDate *JSONTime `json:"driverDepartureDate,omitempty"`
WebUrl *string `json:"webUrl,omitempty"`
Type JourneyScheduleType `json:"type"`
ID *string `json:"id,omitempty"`
PassengerPickupDate OCSSTime `json:"passengerPickupDate" bson:"passengerPickupDate"`
//PassengerDepartureDate *OCSSTime `json:"passengerDepartureDate,omitempty"`
DriverDepartureDate *OCSSTime `json:"driverDepartureDate,omitempty" bson:"driverDepartureDate,omitempty"`
WebUrl *string `json:"webUrl,omitempty" bson:"webUrl,omitempty"`
Type JourneyScheduleType `json:"type"`
}
type DriverJourney struct {
DriverTrip
JourneySchedule
AvailableSteats *int64 `json:"requestedSeats,omitempty"`
Price *Price `json:"price,omitempty"`
AvailableSteats *int64 `json:"requestedSeats,omitempty" bson:"requestedSeats,omitempty"`
Price *Price `json:"price,omitempty" bson:"price,omitempty"`
}
type PassengerJourney struct {
@@ -79,5 +40,5 @@ type PassengerJourney struct {
JourneySchedule
//TODO how to handle requested driverDepartureDate
RequestedSteats *int64 `json:"requestedSeats,omitempty"`
RequestedSteats *int64 `json:"requestedSeats,omitempty" bson:"requestedSeats,omitempty"`
}

View File

@@ -1,9 +1,9 @@
package ocss
type Preferences struct {
Smoking *bool `json:"smoking,omitempty"`
Animals *bool `json:"animals,omitempty"`
Music *bool `json:"music,omitempty"`
IsTalker *bool `json:"isTalker,omitempty"`
LuggageSize *int64 `json:"luggageSize,omitempty"`
Smoking *bool `json:"smoking,omitempty" bson:"smoking,omitempty"`
Animals *bool `json:"animals,omitempty" bson:"animals,omitempty"`
Music *bool `json:"music,omitempty" bson:"music,omitempty"`
IsTalker *bool `json:"isTalker,omitempty" bson:"isTalker,omitempty"`
LuggageSize *int64 `json:"luggageSize,omitempty" bson:"luggageSize,omitempty"`
}

View File

@@ -3,6 +3,11 @@ package ocss
import (
"bytes"
"encoding/json"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
type PriceType int64
@@ -32,6 +37,10 @@ func (s PriceType) MarshalJSON() ([]byte, error) {
return buffer.Bytes(), nil
}
func (s PriceType) MarshalBSONValue() (bsontype.Type, []byte, error) {
return bson.MarshalValue(priceTypeToString[s])
}
func (bs *PriceType) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
@@ -43,8 +52,20 @@ func (bs *PriceType) UnmarshalJSON(b []byte) error {
return nil
}
type Price struct {
Type *PriceType `json:"type,omitempty"`
Amount *float64 `json:"amount,omitempty"`
Currency *string `json:"currency,omitempty"`
func (bs *PriceType) UnmarshalBSONValue(t bsontype.Type, b []byte) error {
if t == bsontype.Null || len(b) == 0 {
return nil
}
j, _, ok := bsoncore.ReadString(b)
if !ok {
return fmt.Errorf("cannot parse status")
}
*bs = priceTypeToID[j]
return nil
}
type Price struct {
Type *PriceType `json:"type,omitempty" bson:"type,omitempty"`
Amount *float64 `json:"amount,omitempty" bson:"amount,omitempty"`
Currency *string `json:"currency,omitempty" bson:"currency,omitempty"`
}

View File

@@ -56,7 +56,7 @@ func (bs *Day) UnmarshalJSON(b []byte) error {
}
type Schedule struct {
PassengerPickupDay *Day `json:"passengerPickupDay,omitempty"`
PassengerPickupDay *Day `json:"passengerPickupDay,omitempty" bson:"passengerPickupDay,omitempty"`
JourneySchedules *[]JourneySchedule `json:"journeySchedules,omitempty"`
JourneySchedules *[]JourneySchedule `json:"journeySchedules,omitempty" bson:"journeySchedules,omitempty"`
}

View File

@@ -97,7 +97,7 @@ type GetPassengerRegularTripsRequest struct {
type PatchBookingsRequest struct {
BookingId string `json:"bookingId"`
Status string `json:"status"`
Message string `json:message"`
Message string `json:"message"`
}
type Server struct {

View File

@@ -4,34 +4,34 @@ import "time"
type Trip struct {
Operator string `json:"operator"`
PassengerPickupLat float64 `json:"passengerPickupLat"`
PassengerPickupLng float64 `json:"passengerPickupLng"`
PassengerDropLat float64 `json:"passengerDropLat"`
PassengerDropLng float64 `json:"passengerDropLng"`
PassengerPickupLat float64 `json:"passengerPickupLat" bson:"passengerPickupLat"`
PassengerPickupLng float64 `json:"passengerPickupLng" bson:"passengerPickupLng"`
PassengerDropLat float64 `json:"passengerDropLat" bson:"passengerDropLat"`
PassengerDropLng float64 `json:"passengerDropLng" bson:"passengerDropLng"`
Duration time.Duration `json:"duration"`
PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty"`
PassengerDropAddress *string `json:"passengerDropAddress,omitempty"`
Distance *int64 `json:"distance,omitempty"`
DriverDepartureLat *float64 `json:"driverDepartureLat,omitempty"`
DriverDepartureLng *float64 `json:"driverDepartureLng,omitempty"`
DriverArrivalLat *float64 `json:"driverArrivalLat,omitempty"`
DriverArrivalLng *float64 `json:"driverArrivalLng,omitempty"`
DriverDepartureAddress *string `json:"driverDepartureAddress,omitempty"`
DriverArrivalAddress *string `json:"driverArrivalAddress,omitempty"`
JourneyPolyline *string `json:"journeyPolyline,omitempty"`
PassengerPickupAddress *string `json:"passengerPickupAddress,omitempty" bson:"passengerPickupAddress,omitempty"`
PassengerDropAddress *string `json:"passengerDropAddress,omitempty" bson:"passengerDropAddress,omitempty"`
Distance *int64 `json:"distance,omitempty" bson:"distance,omitempty"`
DriverDepartureLat *float64 `json:"driverDepartureLat,omitempty" bson:"driverDepartureLat,omitempty"`
DriverDepartureLng *float64 `json:"driverDepartureLng,omitempty" bson:"driverDepartureLng,omitempty"`
DriverArrivalLat *float64 `json:"driverArrivalLat,omitempty" bson:"driverArrivalLat,omitempty"`
DriverArrivalLng *float64 `json:"driverArrivalLng,omitempty" bson:"driverArrivalLng,omitempty"`
DriverDepartureAddress *string `json:"driverDepartureAddress,omitempty" bson:"driverDepartureAddress,omitempty"`
DriverArrivalAddress *string `json:"driverArrivalAddress,omitempty" bson:"driverArrivalAddress,omitempty"`
JourneyPolyline *string `json:"journeyPolyline,omitempty" bson:"journeyPolyline,omitempty"`
//WebUrl *string `json:"webUrl,omitempty"`
Preferences *Preferences `json:"preferences,omitempty"`
Preferences *Preferences `json:"preferences,omitempty" bson:"preferences,omitempty"`
}
type DriverTrip struct {
Driver User `json:"driver"`
DepartureToPickupWalkingDistance *int64 `json:"departureToPickupWalkingDistance,omitempty"`
DepartureToPickupWalkingDuration *time.Duration `json:"departureToPickupWalkingDuration,omitempty"`
DepartureToPickupWalkingPolyline *string `json:"departureToPickupWalkingPolyline,omitempty"`
DropoffToArrivalWalkingDistance *int64 `json:"dropoffToArrivalWalkingDistance,omitempty"`
DropoffToArrivalWalkingDuration *time.Duration `json:"dropoffToArrivalWalkingDuration,omitempty"`
DropoffToArrivalWalkingPolyline *string `json:"dropoffToArrivalWalkingPolyline,omitempty"`
Car *Car `json:"car,omitempty"`
DepartureToPickupWalkingDistance *int64 `json:"departureToPickupWalkingDistance,omitempty" bson:"departureToPickupWalkingDistance,omitempty"`
DepartureToPickupWalkingDuration *time.Duration `json:"departureToPickupWalkingDuration,omitempty" bson:"departureToPickupWalkingDuration,omitempty"`
DepartureToPickupWalkingPolyline *string `json:"departureToPickupWalkingPolyline,omitempty" bson:"departureToPickupWalkingPolyline,omitempty"`
DropoffToArrivalWalkingDistance *int64 `json:"dropoffToArrivalWalkingDistance,omitempty" bson:"dropoffToArrivalWalkingDistance,omitempty"`
DropoffToArrivalWalkingDuration *time.Duration `json:"dropoffToArrivalWalkingDuration,omitempty" bson:"dropoffToArrivalWalkingDuration,omitempty"`
DropoffToArrivalWalkingPolyline *string `json:"dropoffToArrivalWalkingPolyline,omitempty" bson:"dropoffToArrivalWalkingPolyline,omitempty"`
Car *Car `json:"car,omitempty" bson:"car,omitempty"`
Trip
}

View File

@@ -43,14 +43,24 @@ func (bs *Gender) UnmarshalJSON(b []byte) error {
return nil
}
func (g *Gender) ToString() *string {
if g == nil {
return nil
}
res := gendertoString[*g]
return &res
}
type User struct {
ID string `json:"id"`
Operator string `json:"operator"`
Alias string `json:"alias"`
FirstName *string `json:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty"`
Grade *int64 `json:"grade,omitempty"`
Picture *string `json:"picture,omitempty"`
Gender *Gender `json:"gender,omitempty"`
VerifiedIdentity *bool `json:"verifiedIdentity,omitempty"`
FirstName *string `json:"firstName,omitempty" bson:"firstName,omitempty"`
LastName *string `json:"lastName,omitempty" bson:"lastName,omitempty"`
Grade *int64 `json:"grade,omitempty" bson:"grade,omitempty"`
Picture *string `json:"picture,omitempty" bson:"picture,omitempty"`
Gender *Gender `json:"gender,omitempty" bson:"gender,omitempty"`
VerifiedIdentity *bool `json:"verifiedIdentity,omitempty" bson:"verifiedIdentity,omitempty"`
}