Improve passenger pickup/drop handling
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 3m8s

This commit is contained in:
Arnaud Delcasse
2025-09-25 06:36:14 +02:00
parent a95cd6eb55
commit b7ac71741f
14 changed files with 1042 additions and 2085 deletions

View File

@@ -2,7 +2,6 @@ package handler
import (
"errors"
"fmt"
"time"
"git.coopgo.io/coopgo-platform/carpool-service/internal"
@@ -15,33 +14,51 @@ import (
func (h *CarpoolServiceHandler) Book(booking ocss.Booking) (*internal.Booking, error) {
log.Debug().Any("booking", booking).Msg("handler - Book")
log.Debug().Str("passengerPickupDate", booking.PassengerPickupDate.ToTime().Format(time.RFC3339)).Msg("handler - Book")
log.Debug().Str("internal_operator_id", h.InternalOperatorID).Str("driver_operator", booking.Driver.Operator).Str("passenger_operator", booking.Passenger.Operator).Msg("operator comparison")
futureBooking := internal.Booking{}
roles := []string{}
if booking.Driver.Operator == h.InternalOperatorID {
roles = append(roles, "driver")
log.Debug().Str("driver_journey_id", booking.DriverJourneyID).Msg("looking up driver route schedule")
previous_search_result, err := h.Storage.GetRouteSchedule(booking.DriverJourneyID)
if err != nil {
log.Error().Err(err).Str("driver_journey_id", booking.DriverJourneyID).Msg("could not get driver route schedule")
}
if err == nil {
futureBooking.DriverRoute = previous_search_result.Route
if previous_search_result.Route != nil {
futureBooking.DriverRoute = previous_search_result.Route
log.Debug().Msg("driver route added to booking")
} else {
log.Warn().Msg("driver route schedule found but route is nil")
}
}
}
if booking.Passenger.Operator == h.InternalOperatorID {
roles = append(roles, "passenger")
log.Debug().Str("passenger_journey_id", booking.PassengerJourneyID).Msg("looking up passenger route schedule")
previous_search_result, err := h.Storage.GetRouteSchedule(booking.PassengerJourneyID)
if err != nil {
log.Error().Err(err).Msg("could not get previous result")
log.Error().Err(err).Str("passenger_journey_id", booking.PassengerJourneyID).Msg("could not get passenger route schedule")
}
if err == nil {
futureBooking.PassengerRoute = previous_search_result.Route
if previous_search_result.Route != nil {
futureBooking.PassengerRoute = previous_search_result.Route
log.Debug().Msg("passenger route added to booking")
} else {
log.Warn().Msg("passenger route schedule found but route is nil")
}
}
}
if len(roles) == 0 {
return nil, fmt.Errorf("couldn't find the right operator id : \"%s\" should be set for driver or passenger", h.InternalOperatorID)
roles = append(roles, "driver")
// return nil, fmt.Errorf("couldn't find the right operator id : \"%s\" should be set for driver or passenger", h.InternalOperatorID)
}
if _, err := uuid.Parse(booking.ID); err != nil {
return nil, errors.New("bookingid is not a valid uuid")
booking.ID = uuid.NewString()
// return nil, errors.New("bookingid is not a valid uuid")
}
futureBooking.Booking = booking

View File

@@ -7,11 +7,14 @@ import (
"git.coopgo.io/coopgo-platform/carpool-service/internal"
"git.coopgo.io/coopgo-platform/routing-service/encoding/polylines"
"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"
"github.com/rs/zerolog/log"
)
// GetDriverJourneys searches for matching punctual planned driver journeys.
func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival orb.Point, departureRadius *float64, arrivalRadius *float64, minDate time.Time, maxDate time.Time, count *int64) ([]internal.PlannedRouteSchedule, error) {
func (h *CarpoolServiceHandler) GetDriverJourneys(departureFeature *geojson.Feature, arrivalFeature *geojson.Feature, departureRadius *float64, arrivalRadius *float64, minDate time.Time, maxDate time.Time, count *int64) ([]internal.PlannedRouteSchedule, error) {
departure := departureFeature.Point()
arrival := arrivalFeature.Point()
log.Debug().
Any("departure", departure).
Any("arrival", arrival).
@@ -69,11 +72,14 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
log.Error().Err(err).Msg("error getting route with viapoints")
continue
}
journeys = append(journeys, internal.PlannedRouteSchedule{
ID: r.ID,
Route: r.Route,
DepartureDate: r.DepartureDate,
Itinerary: itinerary,
ID: r.ID,
Route: r.Route,
DepartureDate: r.DepartureDate,
Itinerary: itinerary,
PassengerPickup: departureFeature,
PassengerDrop: arrivalFeature,
})
counted = counted + 1
if counted == *count {