carpool-service/interoperability/ocss/journeys_driver_functions.go

137 lines
3.5 KiB
Go

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
}