Return handling
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 40s
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 40s
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h Handler) BookDriverJourney(passengerid string, driverid string, journeyid string) (*types.Booking, error) {
|
||||
func (h Handler) BookDriverJourney(passengerid string, driverid string, journeyid string, returnWaitingDuration time.Duration) (*types.Booking, error) {
|
||||
journey, err := h.Storage.GetDriverJourney(journeyid)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not find driver journey")
|
||||
@@ -21,12 +21,13 @@ func (h Handler) BookDriverJourney(passengerid string, driverid string, journeyi
|
||||
}
|
||||
|
||||
booking := types.Booking{
|
||||
Id: uuid.NewString(),
|
||||
GroupId: uuid.NewString(),
|
||||
Status: "WAITING_CONFIRMATION",
|
||||
PassengerId: passengerid,
|
||||
DriverId: driverid,
|
||||
Journey: journey,
|
||||
Id: uuid.NewString(),
|
||||
GroupId: uuid.NewString(),
|
||||
Status: "WAITING_CONFIRMATION",
|
||||
PassengerId: passengerid,
|
||||
DriverId: driverid,
|
||||
Journey: journey,
|
||||
ReturnWaitingDuration: returnWaitingDuration,
|
||||
}
|
||||
|
||||
if err := h.Storage.CreateBooking(booking); err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/routing-service"
|
||||
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
|
||||
"github.com/google/uuid"
|
||||
"github.com/paulmach/orb"
|
||||
@@ -11,7 +12,9 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson.Feature, departureDate time.Time) ([]*types.DriverJourney, error) {
|
||||
func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson.Feature, departureDate time.Time, noreturn bool) ([]*types.DriverJourney, error) {
|
||||
minDistance := h.Config.GetInt64("parameters.limits.distance.min")
|
||||
maxDistance := h.Config.GetInt64("parameters.limits.distance.max")
|
||||
day := int(departureDate.Weekday())
|
||||
timeInDay := departureDate.Format("15:04")
|
||||
driverJourneys := []*types.DriverJourney{}
|
||||
@@ -26,14 +29,27 @@ func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson
|
||||
for _, a := range availabilities {
|
||||
log.Debug().Any("availability", a).Msg("Availability found")
|
||||
if a.Address != nil {
|
||||
route, err := h.Routing.Route(
|
||||
[]orb.Point{
|
||||
a.Address.Point(),
|
||||
departure.Point(),
|
||||
arrival.Point(),
|
||||
a.Address.Point(),
|
||||
},
|
||||
)
|
||||
var route *routing.Route
|
||||
if noreturn {
|
||||
route, err = h.Routing.Route(
|
||||
[]orb.Point{
|
||||
a.Address.Point(),
|
||||
departure.Point(),
|
||||
arrival.Point(),
|
||||
a.Address.Point(),
|
||||
},
|
||||
)
|
||||
} else {
|
||||
route, err = h.Routing.Route(
|
||||
[]orb.Point{
|
||||
a.Address.Point(),
|
||||
departure.Point(),
|
||||
arrival.Point(),
|
||||
departure.Point(),
|
||||
a.Address.Point(),
|
||||
},
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failedcomputing route request")
|
||||
continue
|
||||
@@ -41,12 +57,17 @@ func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson
|
||||
|
||||
log.Debug().Any("route", route).Msg("debug route")
|
||||
|
||||
passengerDistance := int64(route.Legs[1].Distance)
|
||||
if !noreturn {
|
||||
passengerDistance = passengerDistance + int64(route.Legs[2].Distance)
|
||||
}
|
||||
|
||||
driverJourney := &types.DriverJourney{
|
||||
Id: uuid.NewString(),
|
||||
DriverId: a.DriverId,
|
||||
PassengerPickup: departure,
|
||||
PassengerDrop: arrival,
|
||||
PassengerDistance: int64(route.Legs[1].Distance),
|
||||
PassengerDistance: passengerDistance,
|
||||
DriverDeparture: a.Address,
|
||||
DriverArrival: a.Address,
|
||||
DriverDistance: int64(route.Distance),
|
||||
@@ -58,8 +79,11 @@ func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson
|
||||
Currency: "EUR",
|
||||
Amount: 0,
|
||||
},
|
||||
Noreturn: noreturn,
|
||||
}
|
||||
if driverJourney.PassengerDistance >= minDistance && driverJourney.PassengerDistance <= maxDistance {
|
||||
driverJourneys = append(driverJourneys, driverJourney)
|
||||
}
|
||||
driverJourneys = append(driverJourneys, driverJourney)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,3 +107,52 @@ func (h Handler) GetDriverJourney(driverid string, journeyid string) (*types.Dri
|
||||
|
||||
return journey, nil
|
||||
}
|
||||
|
||||
func (h Handler) ToggleDriverJourneyNoreturn(journeyid string) error {
|
||||
journey, err := h.Storage.GetDriverJourney(journeyid)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error retrieving journey")
|
||||
return err
|
||||
}
|
||||
|
||||
if journey.Noreturn {
|
||||
journey.Noreturn = false
|
||||
route, err := h.Routing.Route(
|
||||
[]orb.Point{
|
||||
journey.DriverDeparture.Point(),
|
||||
journey.PassengerPickup.Point(),
|
||||
journey.PassengerDrop.Point(),
|
||||
journey.PassengerPickup.Point(),
|
||||
journey.DriverDeparture.Point(),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error in route calculation")
|
||||
return err
|
||||
}
|
||||
journey.PassengerDistance = int64(route.Legs[1].Distance) + int64(route.Legs[2].Distance)
|
||||
journey.DriverDistance = int64(route.Distance)
|
||||
journey.Duration = route.Legs[1].Duration + route.Legs[2].Duration
|
||||
} else {
|
||||
journey.Noreturn = true
|
||||
route, err := h.Routing.Route(
|
||||
[]orb.Point{
|
||||
journey.DriverDeparture.Point(),
|
||||
journey.PassengerPickup.Point(),
|
||||
journey.PassengerDrop.Point(),
|
||||
journey.DriverDeparture.Point(),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error in route calculation")
|
||||
return err
|
||||
}
|
||||
journey.PassengerDistance = int64(route.Legs[1].Distance)
|
||||
journey.DriverDistance = int64(route.Distance)
|
||||
journey.Duration = route.Legs[1].Duration
|
||||
}
|
||||
log.Debug().Any("journey", journey).Msg("journey update")
|
||||
|
||||
err = h.Storage.UpdateDriverJourney(*journey)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user