carpool-service/interoperability/ocss/bookings.go

73 lines
2.5 KiB
Go

package ocss
import (
"bytes"
"encoding/json"
"time"
)
type BookingStatus int64
const (
BookingWaitingConfirmation BookingStatus = iota
BookingConfirmed
BookingCancelled
BookingCompletedPendingValidation
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",bson:"_id"` // TODO check uuidv4
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"`
Status BookingStatus `json:"status"`
Distance *int64 `json:"distance,omitempty"`
Duration *time.Duration `json:"duration,omitempty"`
WebUrl *string `json:"webUrl,omitempty"`
Price Price `json:"price"`
Car *Car `json:"car,omitempty"`
DriverJourneyID string `json:"driverJourneyId"`
PassengerJourneyID string `json:"passengerJourneyId"`
}