carpool-service/servers/ocss-api/search.go

95 lines
3.8 KiB
Go

package ocssapi
import (
"context"
"errors"
"time"
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
"github.com/paulmach/orb"
)
func (s *OCSSApiService) GetDriverJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, count *int64) ([]ocss.DriverJourney, error) {
departure := orb.Point{departureLng, departureLat}
arrival := orb.Point{arrivalLng, arrivalLat}
td := 900 * time.Second
if timeDelta != nil {
td = *timeDelta
}
minDate := departureDate.Add(-td * time.Second)
maxDate := departureDate.Add(td * time.Second)
journeys, err := s.Handler.GetDriverJourneys(departure, arrival, departureRadius, arrivalRadius, minDate, maxDate, count)
if err != nil {
return nil, err
}
results := []ocss.DriverJourney{}
for _, j := range journeys {
usermap := j.Route.ExtraMembers["user"].(map[string]any)
journeyId := j.Route.ExtraMembers.MustString("journey_id")
driverDepartureLat := j.Route.Features[0].Point().Lat()
driverDepartureLng := j.Route.Features[0].Point().Lon()
driverArrivalLat := j.Route.Features[1].Point().Lat()
driverArrivalLng := j.Route.Features[1].Point().Lon()
driverDepartureDate := ocss.JSONTime(j.DepartureDate)
duration := time.Duration(0)
var distance *int64
if len(j.Itinerary.Legs) > 2 {
duration = j.Itinerary.Legs[1].Duration
dist := int64(j.Itinerary.Legs[1].Distance)
distance = &dist
}
results = append(results, ocss.DriverJourney{
DriverTrip: ocss.DriverTrip{
Driver: ocss.User{
ID: usermap["id"].(string),
Operator: usermap["opeator"].(string),
Alias: usermap["alias"].(string),
},
Trip: ocss.Trip{
Operator: "ridygo.fr",
PassengerPickupLat: departureLat,
PassengerPickupLng: departureLng,
PassengerDropLat: arrivalLat,
PassengerDropLng: arrivalLng,
DriverDepartureLat: &driverDepartureLat,
DriverDepartureLng: &driverDepartureLng,
DriverArrivalLat: &driverArrivalLat,
DriverArrivalLng: &driverArrivalLng,
Duration: duration,
Distance: distance,
},
},
JourneySchedule: ocss.JourneySchedule{
ID: &journeyId,
PassengerPickupDate: ocss.JSONTime(j.DepartureDate.Add(j.Itinerary.Legs[0].Duration)),
DriverDepartureDate: &driverDepartureDate,
Type: ocss.Planned,
},
// Price: &ocss.Price{
// Amount: ,
// Currency: "EUR",
// },
})
}
return results, nil
}
func (s *OCSSApiService) GetPassengerJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, count *int64) ([]ocss.PassengerJourney, error) {
return nil, errors.New("method not implmeented - GetPassengerJourneys")
}
func (s *OCSSApiService) GetDriverRegularTrips(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureTimeOfDay string, departureWeekDays *[]string, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, minDepartureDate *time.Time, maxDepartureDate *time.Time, count *int64) ([]ocss.DriverTrip, error) {
return []ocss.DriverTrip{}, nil
}
func (s *OCSSApiService) GetPassengerRegularTrips(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureTimeOfDay string, departureWeekDays *[]string, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, minDepartureDate *time.Time, maxDepartureDate *time.Time, count *int64) ([]ocss.PassengerTrip, error) {
return []ocss.PassengerTrip{}, nil
}