carpool-service/interoperability/ocss/journeys.go

75 lines
1.6 KiB
Go
Raw Normal View History

2023-03-27 18:54:56 +00:00
package ocss
import (
2023-03-30 06:44:58 +00:00
"encoding/json"
2023-03-27 18:54:56 +00:00
"fmt"
"time"
)
type JourneyScheduleType int64
const (
Planned JourneyScheduleType = iota
Dynamic
Line
)
func (t JourneyScheduleType) MarshalJSON() ([]byte, error) {
types := map[JourneyScheduleType]string{
Planned: "\"PLANNED\"",
Dynamic: "\"DYNAMIC\"",
Line: "\"Line\"",
}
return []byte(types[t]), nil
}
type JSONTime time.Time
func (t JSONTime) MarshalJSON() ([]byte, error) {
//do your serializing here
stamp := fmt.Sprintf("%v", time.Time(t).Unix())
return []byte(stamp), nil
}
2023-03-30 06:44:58 +00:00
func (t *JSONTime) UnmarshalJSON(b []byte) error {
var timestamp int64
err := json.Unmarshal(b, &timestamp)
if err != nil {
return err
}
parsed := time.Unix(timestamp, 0)
if err != nil {
return err
}
jsontime := JSONTime(parsed)
*t = jsontime
return nil
}
2023-03-27 18:54:56 +00:00
type JourneySchedule struct {
ID *string `json:"id,omitempty"`
PassengerPickupDate JSONTime `json:"passengerPickupDate"`
PassengerDepartureDate *JSONTime `json:"passengerDepartureDate,omitempty"`
DriverDepartureDate *JSONTime `json:"driverDepartureDate,omitempty"`
WebUrl *string `json:"webUrl,omitempty"`
Type JourneyScheduleType `json:"type"`
}
type DriverJourney struct {
DriverTrip
JourneySchedule
AvailableSteats *int `json:"requestedSeats,omitempty"`
Price *Price `json:"price,omitempty"`
}
type PassengerJourney struct {
PassengerTrip
JourneySchedule
//TODO how to handle requested driverDepartureDate
RequestedSteats *int64 `json:"requestedSeats,omitempty"`
}