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"`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ocss
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
@@ -31,6 +32,22 @@ func (t JSONTime) MarshalJSON() ([]byte, error) {
|
||||
return []byte(stamp), nil
|
||||
}
|
||||
|
||||
func (t *JSONTime) UnmarshalJSON(b []byte) error {
|
||||
var timestamp int64
|
||||
err := json.Unmarshal(b, ×tamp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
parsed := time.Unix(timestamp, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsontime := JSONTime(parsed)
|
||||
*t = jsontime
|
||||
return nil
|
||||
}
|
||||
|
||||
type JourneySchedule struct {
|
||||
ID *string `json:"id,omitempty"`
|
||||
PassengerPickupDate JSONTime `json:"passengerPickupDate"`
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package ocss
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type PriceType int64
|
||||
|
||||
const (
|
||||
@@ -8,6 +13,36 @@ const (
|
||||
Unknown
|
||||
)
|
||||
|
||||
var priceTypeToID = map[string]PriceType{
|
||||
"FREE": Free,
|
||||
"PAYING": Paying,
|
||||
"UNKNOWN": Unknown,
|
||||
}
|
||||
|
||||
var priceTypeToString = map[PriceType]string{
|
||||
Free: "FREE",
|
||||
Paying: "PAYING",
|
||||
Unknown: "UNKNOWN",
|
||||
}
|
||||
|
||||
func (s PriceType) MarshalJSON() ([]byte, error) {
|
||||
buffer := bytes.NewBufferString(`"`)
|
||||
buffer.WriteString(priceTypeToString[s])
|
||||
buffer.WriteString(`"`)
|
||||
return buffer.Bytes(), nil
|
||||
}
|
||||
|
||||
func (bs *PriceType) 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 = priceTypeToID[j]
|
||||
return nil
|
||||
}
|
||||
|
||||
type Price struct {
|
||||
Type *PriceType `json:"type,omitempty"`
|
||||
Amount *float64 `json:"amount,omitempty"`
|
||||
|
||||
@@ -418,13 +418,15 @@ func (s *Server) patchBookings(w http.ResponseWriter, bookingId string, r *http.
|
||||
|
||||
func (s *Server) getBookings(w http.ResponseWriter, bookingId string, r *http.Request) {
|
||||
|
||||
log.Debug().Str("booking id", bookingId).Msg("GetBooking request")
|
||||
|
||||
booking, err := s.Handler.GetBookings(
|
||||
r.Context(),
|
||||
bookingId,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error in PatchBookings")
|
||||
log.Error().Err(err).Msg("error in GetBookings")
|
||||
jsonError(w, err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user