210 lines
6.3 KiB
Go
210 lines
6.3 KiB
Go
package proto
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
|
|
)
|
|
|
|
func (j *CarpoolServiceDriverJourney) ToOCSS() ocss.DriverJourney {
|
|
|
|
var departureToPickupWalkingDuration *time.Duration
|
|
if j.DepartureToPickupWalkingDuration != nil {
|
|
dtpw := time.Duration(*j.DepartureToPickupWalkingDuration)
|
|
departureToPickupWalkingDuration = &dtpw
|
|
}
|
|
|
|
var dropoffToArrivalWalkingDuration *time.Duration
|
|
if j.DropoffToArrivalWalkingDuration != nil {
|
|
dtpw := time.Duration(*j.DropoffToArrivalWalkingDuration)
|
|
dropoffToArrivalWalkingDuration = &dtpw
|
|
}
|
|
|
|
var car *ocss.Car
|
|
if j.Car != nil {
|
|
car = &ocss.Car{
|
|
Model: j.Car.Model,
|
|
Brand: j.Car.Brand,
|
|
}
|
|
}
|
|
|
|
var preferences *ocss.Preferences
|
|
if j.Preferences != nil {
|
|
preferences = &ocss.Preferences{
|
|
Smoking: j.Preferences.Smoking,
|
|
Animals: j.Preferences.Animals,
|
|
Music: j.Preferences.Music,
|
|
IsTalker: j.Preferences.IsTalker,
|
|
LuggageSize: j.Preferences.LuggageSize,
|
|
}
|
|
}
|
|
|
|
var driverDepartureDate *ocss.JSONTime
|
|
if j.DriverDepartureDate != nil {
|
|
ddd := ocss.JSONTime(j.DriverDepartureDate.AsTime())
|
|
driverDepartureDate = &ddd
|
|
}
|
|
|
|
var price *ocss.Price
|
|
if j.Price != nil {
|
|
var priceType *ocss.PriceType
|
|
if j.Price.Type != nil {
|
|
if *j.Price.Type == CarpoolServicePriceType_FREE {
|
|
pt := ocss.Free
|
|
priceType = &pt
|
|
} else if *j.Price.Type == CarpoolServicePriceType_PAYING {
|
|
pt := ocss.Paying
|
|
priceType = &pt
|
|
} else if *j.Price.Type == CarpoolServicePriceType_UNKNOWN {
|
|
pt := ocss.Unknown
|
|
priceType = &pt
|
|
}
|
|
}
|
|
price = &ocss.Price{
|
|
Amount: j.Price.Amount,
|
|
Currency: j.Price.Currency,
|
|
Type: priceType,
|
|
}
|
|
}
|
|
|
|
return ocss.DriverJourney{
|
|
DriverTrip: ocss.DriverTrip{
|
|
Driver: ocss.User{
|
|
ID: j.Driver.Id,
|
|
Operator: j.Driver.Operator,
|
|
Alias: j.Driver.Alias,
|
|
FirstName: j.Driver.FirstName,
|
|
LastName: j.Driver.LastName,
|
|
Grade: j.Driver.Grade,
|
|
Picture: j.Driver.Picture,
|
|
Gender: GenderToOCSS(j.Driver.Gender),
|
|
VerifiedIdentity: j.Driver.VerifiedIdentity,
|
|
},
|
|
DepartureToPickupWalkingDistance: j.DepartureToPickupWalkingDistance,
|
|
DepartureToPickupWalkingDuration: departureToPickupWalkingDuration,
|
|
DepartureToPickupWalkingPolyline: j.DepartureToPickupWalkingPolyline,
|
|
DropoffToArrivalWalkingDistance: j.DropoffToArrivalWalkingDistance,
|
|
DropoffToArrivalWalkingDuration: dropoffToArrivalWalkingDuration,
|
|
DropoffToArrivalWalkingPolyline: j.DropoffToArrivalWalkingPolyline,
|
|
Car: car,
|
|
Trip: ocss.Trip{
|
|
Operator: j.Operator,
|
|
PassengerPickupLat: j.PassengerPickupLat,
|
|
PassengerPickupLng: j.PassengerPickupLng,
|
|
PassengerDropLat: j.PassengerDropLat,
|
|
PassengerDropLng: j.PassengerDropLng,
|
|
PassengerPickupAddress: j.PassengerPickupAddress,
|
|
PassengerDropAddress: j.PassengerDropAddress,
|
|
Duration: time.Duration(j.Duration),
|
|
Distance: j.Distance,
|
|
DriverDepartureLat: j.DriverDepartureLat,
|
|
DriverDepartureLng: j.DriverDepartureLng,
|
|
DriverArrivalLat: j.DriverArrivalLat,
|
|
DriverArrivalLng: j.DriverArrivalLng,
|
|
DriverDepartureAddress: j.DriverDepartureAddress,
|
|
DriverArrivalAddress: j.DriverArrivalAddress,
|
|
JourneyPolyline: j.JourneyPolyline,
|
|
Preferences: preferences,
|
|
},
|
|
},
|
|
JourneySchedule: ocss.JourneySchedule{
|
|
PassengerPickupDate: ocss.JSONTime(j.PassengerPickupDate.AsTime()),
|
|
DriverDepartureDate: driverDepartureDate,
|
|
WebUrl: j.WebUrl,
|
|
Type: j.Type.ToOCSS(),
|
|
},
|
|
AvailableSteats: j.AvailableSeats,
|
|
Price: price,
|
|
}
|
|
}
|
|
|
|
func (j *CarpoolServicePassengerJourney) ToOCSS() ocss.PassengerJourney {
|
|
|
|
var preferences *ocss.Preferences
|
|
if j.Preferences != nil {
|
|
preferences = &ocss.Preferences{
|
|
Smoking: j.Preferences.Smoking,
|
|
Animals: j.Preferences.Animals,
|
|
Music: j.Preferences.Music,
|
|
IsTalker: j.Preferences.IsTalker,
|
|
LuggageSize: j.Preferences.LuggageSize,
|
|
}
|
|
}
|
|
|
|
var driverDepartureDate *ocss.JSONTime
|
|
if j.DriverDepartureDate != nil {
|
|
ddd := ocss.JSONTime(j.DriverDepartureDate.AsTime())
|
|
driverDepartureDate = &ddd
|
|
}
|
|
|
|
return ocss.PassengerJourney{
|
|
PassengerTrip: ocss.PassengerTrip{
|
|
Passenger: ocss.User{
|
|
ID: j.Passenger.Id,
|
|
Operator: j.Passenger.Operator,
|
|
Alias: j.Passenger.Alias,
|
|
FirstName: j.Passenger.FirstName,
|
|
LastName: j.Passenger.LastName,
|
|
Grade: j.Passenger.Grade,
|
|
Picture: j.Passenger.Picture,
|
|
Gender: GenderToOCSS(j.Passenger.Gender),
|
|
VerifiedIdentity: j.Passenger.VerifiedIdentity,
|
|
},
|
|
Trip: ocss.Trip{
|
|
Operator: j.Operator,
|
|
PassengerPickupLat: j.PassengerPickupLat,
|
|
PassengerPickupLng: j.PassengerPickupLng,
|
|
PassengerDropLat: j.PassengerDropLat,
|
|
PassengerDropLng: j.PassengerDropLng,
|
|
PassengerPickupAddress: j.PassengerPickupAddress,
|
|
PassengerDropAddress: j.PassengerDropAddress,
|
|
Duration: time.Duration(j.Duration),
|
|
Distance: j.Distance,
|
|
DriverDepartureLat: j.DriverDepartureLat,
|
|
DriverDepartureLng: j.DriverDepartureLng,
|
|
DriverArrivalLat: j.DriverArrivalLat,
|
|
DriverArrivalLng: j.DriverArrivalLng,
|
|
DriverDepartureAddress: j.DriverDepartureAddress,
|
|
DriverArrivalAddress: j.DriverArrivalAddress,
|
|
JourneyPolyline: j.JourneyPolyline,
|
|
Preferences: preferences,
|
|
},
|
|
},
|
|
JourneySchedule: ocss.JourneySchedule{
|
|
PassengerPickupDate: ocss.JSONTime(j.PassengerPickupDate.AsTime()),
|
|
DriverDepartureDate: driverDepartureDate,
|
|
WebUrl: j.WebUrl,
|
|
Type: j.Type.ToOCSS(),
|
|
},
|
|
RequestedSteats: j.RequestedSeats,
|
|
}
|
|
}
|
|
|
|
func (t CarpoolServiceJourneyType) ToOCSS() ocss.JourneyScheduleType {
|
|
if t == CarpoolServiceJourneyType_DYNAMIC {
|
|
return ocss.Dynamic
|
|
} else if t == CarpoolServiceJourneyType_LINE {
|
|
return ocss.Line
|
|
} else {
|
|
return ocss.Planned
|
|
}
|
|
}
|
|
|
|
func GenderToOCSS(g *string) *ocss.Gender {
|
|
if g == nil {
|
|
return nil
|
|
}
|
|
|
|
var gender ocss.Gender
|
|
|
|
if *g == "F" {
|
|
gender = ocss.Female
|
|
} else if *g == "M" {
|
|
gender = ocss.Male
|
|
} else if *g == "O" {
|
|
gender = ocss.Other
|
|
}
|
|
|
|
return &gender
|
|
}
|