Add PostgreSQL database option and more booking flow functionalities
This commit is contained in:
136
interoperability/ocss/journeys_driver_functions.go
Normal file
136
interoperability/ocss/journeys_driver_functions.go
Normal file
@@ -0,0 +1,136 @@
|
||||
package ocss
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
geojson "github.com/paulmach/orb/geojson"
|
||||
)
|
||||
|
||||
func NewDriverJourney(
|
||||
id string,
|
||||
operator string,
|
||||
driver User,
|
||||
passengerPickup geojson.Feature,
|
||||
passengerDrop geojson.Feature,
|
||||
duration time.Duration,
|
||||
passengerPickupDate time.Time,
|
||||
journeyType JourneyScheduleType,
|
||||
) *DriverJourney {
|
||||
var pickupAddress *string
|
||||
if addr := passengerPickup.Properties.MustString("label", ""); addr != "" {
|
||||
pickupAddress = &addr
|
||||
}
|
||||
var dropAddress *string
|
||||
if addr := passengerDrop.Properties.MustString("label", ""); addr != "" {
|
||||
dropAddress = &addr
|
||||
}
|
||||
|
||||
return &DriverJourney{
|
||||
DriverTrip: DriverTrip{
|
||||
Driver: driver,
|
||||
Trip: Trip{
|
||||
Operator: operator,
|
||||
PassengerPickupLat: passengerPickup.Point().Lat(),
|
||||
PassengerPickupLng: passengerPickup.Point().Lon(),
|
||||
PassengerPickupAddress: pickupAddress,
|
||||
PassengerDropLat: passengerDrop.Point().Lat(),
|
||||
PassengerDropLng: passengerDrop.Point().Lon(),
|
||||
PassengerDropAddress: dropAddress,
|
||||
Duration: duration,
|
||||
},
|
||||
},
|
||||
JourneySchedule: JourneySchedule{
|
||||
ID: &id,
|
||||
PassengerPickupDate: OCSSTime(passengerPickupDate),
|
||||
Type: journeyType,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddDepartureToPickupWalkingDistance(distance int64) *DriverJourney {
|
||||
j.DepartureToPickupWalkingDistance = &distance
|
||||
return j
|
||||
}
|
||||
func (j *DriverJourney) AddDepartureToPickupWalkingDuration(duration time.Duration) *DriverJourney {
|
||||
j.DepartureToPickupWalkingDuration = &duration
|
||||
return j
|
||||
}
|
||||
func (j *DriverJourney) AddDepartureToPickupWalkingPolyline(polyline string) *DriverJourney {
|
||||
j.DepartureToPickupWalkingPolyline = &polyline
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddDropoffToArrivalWalkingDistance(distance int64) *DriverJourney {
|
||||
j.DropoffToArrivalWalkingDistance = &distance
|
||||
return j
|
||||
}
|
||||
func (j *DriverJourney) AddDropoffToArrivalWalkingDuration(duration time.Duration) *DriverJourney {
|
||||
j.DropoffToArrivalWalkingDuration = &duration
|
||||
return j
|
||||
}
|
||||
func (j *DriverJourney) AddDropoffToArrivalWalkingPolyline(polyline string) *DriverJourney {
|
||||
j.DropoffToArrivalWalkingPolyline = &polyline
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddCar(car Car) *DriverJourney {
|
||||
j.Car = &car
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddDriverDeparture(location geojson.Feature) *DriverJourney {
|
||||
lat := location.Point().Lat()
|
||||
lon := location.Point().Lon()
|
||||
|
||||
j.DriverDepartureLat = &lat
|
||||
j.DriverDepartureLng = &lon
|
||||
if addr := location.Properties.MustString("label", ""); addr != "" {
|
||||
j.DriverDepartureAddress = &addr
|
||||
}
|
||||
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddDriverArrival(location geojson.Feature) *DriverJourney {
|
||||
lat := location.Point().Lat()
|
||||
lon := location.Point().Lon()
|
||||
|
||||
j.DriverArrivalLat = &lat
|
||||
j.DriverArrivalLng = &lon
|
||||
if addr := location.Properties.MustString("label", ""); addr != "" {
|
||||
j.DriverArrivalAddress = &addr
|
||||
}
|
||||
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddDistance(distance int64) *DriverJourney {
|
||||
j.Distance = &distance
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddJourneyPolyline(polyline string) *DriverJourney {
|
||||
j.JourneyPolyline = &polyline
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddPreferences(preferences Preferences) *DriverJourney {
|
||||
j.Preferences = &preferences
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddAvailableSeats(seats int64) *DriverJourney {
|
||||
j.AvailableSteats = &seats
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddDriverDepartureDate(date time.Time) *DriverJourney {
|
||||
d := OCSSTime(date)
|
||||
j.DriverDepartureDate = &d
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *DriverJourney) AddWebUrl(url string) *DriverJourney {
|
||||
j.WebUrl = &url
|
||||
return j
|
||||
}
|
||||
105
interoperability/ocss/journeys_passenger_functions.go
Normal file
105
interoperability/ocss/journeys_passenger_functions.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package ocss
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
geojson "github.com/paulmach/orb/geojson"
|
||||
)
|
||||
|
||||
func NewPassengerJourney(
|
||||
id string,
|
||||
operator string,
|
||||
driver User,
|
||||
passengerPickup geojson.Feature,
|
||||
passengerDrop geojson.Feature,
|
||||
duration time.Duration,
|
||||
passengerPickupDate time.Time,
|
||||
journeyType JourneyScheduleType,
|
||||
) *PassengerJourney {
|
||||
var pickupAddress *string
|
||||
if addr := passengerPickup.Properties.MustString("label", ""); addr != "" {
|
||||
pickupAddress = &addr
|
||||
}
|
||||
var dropAddress *string
|
||||
if addr := passengerDrop.Properties.MustString("label", ""); addr != "" {
|
||||
dropAddress = &addr
|
||||
}
|
||||
|
||||
return &PassengerJourney{
|
||||
PassengerTrip: PassengerTrip{
|
||||
Passenger: driver,
|
||||
Trip: Trip{
|
||||
Operator: operator,
|
||||
PassengerPickupLat: passengerPickup.Point().Lat(),
|
||||
PassengerPickupLng: passengerPickup.Point().Lon(),
|
||||
PassengerPickupAddress: pickupAddress,
|
||||
PassengerDropLat: passengerDrop.Point().Lat(),
|
||||
PassengerDropLng: passengerDrop.Point().Lon(),
|
||||
PassengerDropAddress: dropAddress,
|
||||
Duration: duration,
|
||||
},
|
||||
},
|
||||
JourneySchedule: JourneySchedule{
|
||||
ID: &id,
|
||||
PassengerPickupDate: OCSSTime(passengerPickupDate),
|
||||
Type: journeyType,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddDriverDeparture(location geojson.Feature) *PassengerJourney {
|
||||
lat := location.Point().Lat()
|
||||
lon := location.Point().Lon()
|
||||
|
||||
j.DriverDepartureLat = &lat
|
||||
j.DriverDepartureLng = &lon
|
||||
if addr := location.Properties.MustString("label", ""); addr != "" {
|
||||
j.DriverDepartureAddress = &addr
|
||||
}
|
||||
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddDriverArrival(location geojson.Feature) *PassengerJourney {
|
||||
lat := location.Point().Lat()
|
||||
lon := location.Point().Lon()
|
||||
|
||||
j.DriverArrivalLat = &lat
|
||||
j.DriverArrivalLng = &lon
|
||||
if addr := location.Properties.MustString("label", ""); addr != "" {
|
||||
j.DriverArrivalAddress = &addr
|
||||
}
|
||||
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddDistance(distance int64) *PassengerJourney {
|
||||
j.Distance = &distance
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddJourneyPolyline(polyline string) *PassengerJourney {
|
||||
j.JourneyPolyline = &polyline
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddPreferences(preferences Preferences) *PassengerJourney {
|
||||
j.Preferences = &preferences
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddAvailableSeats(seats int64) *PassengerJourney {
|
||||
j.RequestedSteats = &seats
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddDriverDepartureDate(date time.Time) *PassengerJourney {
|
||||
d := OCSSTime(date)
|
||||
j.DriverDepartureDate = &d
|
||||
return j
|
||||
}
|
||||
|
||||
func (j *PassengerJourney) AddWebUrl(url string) *PassengerJourney {
|
||||
j.WebUrl = &url
|
||||
return j
|
||||
}
|
||||
62
interoperability/ocss/time.go
Normal file
62
interoperability/ocss/time.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package ocss
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
|
||||
)
|
||||
|
||||
type OCSSTime time.Time
|
||||
|
||||
func (t OCSSTime) MarshalJSON() ([]byte, error) {
|
||||
//do your serializing here
|
||||
stamp := fmt.Sprintf("%v", time.Time(t).Unix())
|
||||
return []byte(stamp), nil
|
||||
}
|
||||
|
||||
func (v OCSSTime) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
return bson.MarshalValue(time.Time(v))
|
||||
}
|
||||
|
||||
func (t *OCSSTime) 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
|
||||
}
|
||||
|
||||
ocsstime := OCSSTime(parsed)
|
||||
*t = ocsstime
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *OCSSTime) UnmarshalBSONValue(bt bsontype.Type, b []byte) error {
|
||||
|
||||
if bt == bsontype.Null || len(b) == 0 {
|
||||
return nil
|
||||
}
|
||||
datetime, _, ok := bsoncore.ReadTime(b)
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot parse time")
|
||||
}
|
||||
|
||||
*t = OCSSTime(datetime)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *OCSSTime) ToTime() *time.Time {
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
time := time.Time(*t)
|
||||
return &time
|
||||
}
|
||||
Reference in New Issue
Block a user