Add driver exclusion by group id
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m56s

This commit is contained in:
Arnaud Delcasse
2026-01-14 10:36:02 +01:00
parent 606b84a60a
commit 8875adbcbb
6 changed files with 51 additions and 16 deletions

View File

@@ -12,14 +12,28 @@ import (
"github.com/rs/zerolog/log"
)
func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson.Feature, departureDate time.Time, noreturn bool) ([]*types.DriverJourney, error) {
log.Info().Time("departureDate", departureDate).Bool("noreturn", noreturn).Str("departure", departure.Properties.MustString("label")).Str("arrival", arrival.Properties.MustString("label")).Msg("calling GetDriverJourneys")
func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson.Feature, departureDate time.Time, noreturn bool, excludeGroupId string) ([]*types.DriverJourney, error) {
log.Info().Time("departureDate", departureDate).Bool("noreturn", noreturn).Str("departure", departure.Properties.MustString("label")).Str("arrival", arrival.Properties.MustString("label")).Str("excludeGroupId", excludeGroupId).Msg("calling GetDriverJourneys")
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{}
// Build map of drivers to exclude based on group_id
excludedDrivers := make(map[string]bool)
if excludeGroupId != "" {
bookings, err := h.Storage.GetBookingsByGroupId(excludeGroupId)
if err != nil {
log.Warn().Err(err).Str("group_id", excludeGroupId).Msg("could not get bookings by group_id for exclusion")
} else {
for _, booking := range bookings {
excludedDrivers[booking.DriverId] = true
log.Debug().Str("driver_id", booking.DriverId).Str("group_id", excludeGroupId).Msg("excluding driver from search")
}
}
}
// Get Availabilities
availabilities, err := h.Storage.GetRegularAvailabilities(day, timeInDay)
if err != nil {
@@ -28,6 +42,11 @@ func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson
}
for _, a := range availabilities {
// Skip excluded drivers
if excludedDrivers[a.DriverId] {
continue
}
if a.Address != nil {
var route *routing.Route
if noreturn {