2023-03-27 18:54:56 +00:00
|
|
|
package ocss
|
|
|
|
|
2023-03-30 06:44:58 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"time"
|
|
|
|
)
|
2023-03-27 18:54:56 +00:00
|
|
|
|
|
|
|
type BookingStatus int64
|
|
|
|
|
|
|
|
const (
|
|
|
|
BookingWaitingConfirmation BookingStatus = iota
|
|
|
|
BookingConfirmed
|
|
|
|
BookingCancelled
|
|
|
|
BookingCompletedPendingValidation
|
|
|
|
BookingValidated
|
|
|
|
)
|
|
|
|
|
2023-03-30 06:44:58 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-03-27 18:54:56 +00:00
|
|
|
type Booking struct {
|
2023-03-30 06:44:58 +00:00
|
|
|
ID string `json:"id",bson:"_id"` // TODO check uuidv4
|
|
|
|
Driver User `json:"driver"`
|
2023-03-27 18:54:56 +00:00
|
|
|
Passenger User `json:"passenger"`
|
2023-03-30 06:44:58 +00:00
|
|
|
PassengerPickupDate JSONTime `json:"passengerPickupDate"`
|
2023-03-27 18:54:56 +00:00
|
|
|
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"`
|
|
|
|
Status BookingStatus `json:"status"`
|
|
|
|
Distance *int64 `json:"distance,omitempty"`
|
|
|
|
Duration *time.Duration `json:"duration,omitempty"`
|
|
|
|
WebUrl *string `json:"webUrl,omitempty"`
|
|
|
|
Price Price `json:"price"`
|
2023-03-30 06:44:58 +00:00
|
|
|
Car *Car `json:"car,omitempty"`
|
2023-03-27 18:54:56 +00:00
|
|
|
DriverJourneyID string `json:"driverJourneyId"`
|
|
|
|
PassengerJourneyID string `json:"passengerJourneyId"`
|
|
|
|
}
|