regular routes journeys, persistent KV to store return states, ...

This commit is contained in:
2023-04-03 20:35:12 +02:00
parent 0ae5730e7f
commit 2f536dfb19
21 changed files with 1722 additions and 1070 deletions

View File

@@ -1,6 +1,10 @@
package ocss
import "time"
import (
"bytes"
"encoding/json"
"time"
)
type CarpoolBookingStatus int64
@@ -12,6 +16,40 @@ const (
CarpoolBookingValidated
)
var carpoolBookingStatustoID = map[string]CarpoolBookingStatus{
"WAITING_CONFIRMATION": CarpoolBookingWaitingConfirmation,
"CONFIRMED": CarpoolBookingConfirmed,
"CANCELLED": CarpoolBookingCancelled,
"COMPLETED_PENDING_VALIDATION": CarpoolBookingCompletedPendingValidation,
"VALIDATED": CarpoolBookingValidated,
}
var carpoolBookingStatustoString = map[CarpoolBookingStatus]string{
CarpoolBookingWaitingConfirmation: "WAITING_CONFIRMATION",
CarpoolBookingConfirmed: "CONFIRMED",
CarpoolBookingCancelled: "CANCELLED",
CarpoolBookingCompletedPendingValidation: "COMPLETED_PENDING_VALIDATION",
CarpoolBookingValidated: "VALIDATED",
}
func (s CarpoolBookingStatus) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(carpoolBookingStatustoString[s])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
func (bs *CarpoolBookingStatus) 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 = carpoolBookingStatustoID[j]
return nil
}
type CarpoolBookingEventData struct {
CarpoolBooking
DriverCarpoolBooking

View File

@@ -48,6 +48,15 @@ func (t *JSONTime) UnmarshalJSON(b []byte) error {
return nil
}
func (t *JSONTime) ToTime() *time.Time {
if t == nil {
return nil
}
time := time.Time(*t)
return &time
}
type JourneySchedule struct {
ID *string `json:"id,omitempty"`
PassengerPickupDate JSONTime `json:"passengerPickupDate"`
@@ -61,7 +70,7 @@ type DriverJourney struct {
DriverTrip
JourneySchedule
AvailableSteats *int `json:"requestedSeats,omitempty"`
AvailableSteats *int64 `json:"requestedSeats,omitempty"`
Price *Price `json:"price,omitempty"`
}

View File

@@ -1,5 +1,10 @@
package ocss
import (
"bytes"
"encoding/json"
)
type Day int64
const (
@@ -12,6 +17,44 @@ const (
Sunday
)
var daytoID = map[string]Day{
"MON": Monday,
"TUE": Tuesday,
"WED": Wednesday,
"THU": Thursday,
"FRI": Friday,
"SAT": Saturday,
"SUN": Sunday,
}
var daytoString = map[Day]string{
Monday: "MON",
Tuesday: "TUE",
Wednesday: "WED",
Thursday: "THU",
Friday: "FRI",
Saturday: "SAT",
Sunday: "SUN",
}
func (s Day) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(daytoString[s])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
func (bs *Day) 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 = daytoID[j]
return nil
}
type Schedule struct {
PassengerPickupDay *Day `json:"passengerPickupDay,omitempty"`

View File

@@ -1,5 +1,10 @@
package ocss
import (
"bytes"
"encoding/json"
)
type Gender int64
const (
@@ -8,6 +13,36 @@ const (
Other
)
var gendertoID = map[string]Gender{
"F": Female,
"M": Male,
"O": Other,
}
var gendertoString = map[Gender]string{
Female: "F",
Male: "M",
Other: "O",
}
func (s Gender) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(gendertoString[s])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
func (bs *Gender) 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 = gendertoID[j]
return nil
}
type User struct {
ID string `json:"id"`
Operator string `json:"operator"`