Add PostgreSQL database option and more booking flow functionalities
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user