Add driver exclusion by group id
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m56s
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m56s
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -207,7 +207,7 @@ func TestHandler_GetDriverJourneys(t *testing.T) {
|
||||
Routing: mockRouting,
|
||||
}
|
||||
|
||||
journeys, err := handler.GetDriverJourneys(departure, arrival, tt.departureDate, tt.noreturn)
|
||||
journeys, err := handler.GetDriverJourneys(departure, arrival, tt.departureDate, tt.noreturn, "")
|
||||
|
||||
assert.NoError(t, err, tt.description)
|
||||
assert.Len(t, journeys, tt.expectedJourneys, tt.description)
|
||||
|
||||
Reference in New Issue
Block a user