Booking
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package ocss
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BookingStatus int64
|
||||
|
||||
@@ -12,11 +16,45 @@ const (
|
||||
BookingValidated
|
||||
)
|
||||
|
||||
var bookingStatustoID = map[string]BookingStatus{
|
||||
"WAITING_CONFIRMATION": BookingWaitingConfirmation,
|
||||
"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",
|
||||
}
|
||||
|
||||
func (s BookingStatus) MarshalJSON() ([]byte, error) {
|
||||
buffer := bytes.NewBufferString(`"`)
|
||||
buffer.WriteString(bookingStatustoString[s])
|
||||
buffer.WriteString(`"`)
|
||||
return buffer.Bytes(), nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
type Booking struct {
|
||||
ID string `json:"id"` // TODO check uuidv4
|
||||
Driver User `json:"driver"`
|
||||
ID string `json:"id",bson:"_id"` // TODO check uuidv4
|
||||
Driver User `json:"driver"`
|
||||
Passenger User `json:"passenger"`
|
||||
PassengerPickupDate time.Time `json:"passengerPickupDate"`
|
||||
PassengerPickupDate JSONTime `json:"passengerPickupDate"`
|
||||
PassengerPickupLat float64 `json:"passengerPickupLat"`
|
||||
PassengerPickupLng float64 `json:"passengerPickupLng"`
|
||||
PassengerDropLat float64 `json:"passengerDropLat"`
|
||||
@@ -28,7 +66,7 @@ type Booking struct {
|
||||
Duration *time.Duration `json:"duration,omitempty"`
|
||||
WebUrl *string `json:"webUrl,omitempty"`
|
||||
Price Price `json:"price"`
|
||||
Car *Car `json:"car"`
|
||||
Car *Car `json:"car,omitempty"`
|
||||
DriverJourneyID string `json:"driverJourneyId"`
|
||||
PassengerJourneyID string `json:"passengerJourneyId"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user