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"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson.Feature, departureDate time.Time, noreturn bool) ([]*types.DriverJourney, error) {
|
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")).Msg("calling GetDriverJourneys")
|
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")
|
minDistance := h.Config.GetInt64("parameters.limits.distance.min")
|
||||||
maxDistance := h.Config.GetInt64("parameters.limits.distance.max")
|
maxDistance := h.Config.GetInt64("parameters.limits.distance.max")
|
||||||
day := int(departureDate.Weekday())
|
day := int(departureDate.Weekday())
|
||||||
timeInDay := departureDate.Format("15:04")
|
timeInDay := departureDate.Format("15:04")
|
||||||
driverJourneys := []*types.DriverJourney{}
|
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
|
// Get Availabilities
|
||||||
availabilities, err := h.Storage.GetRegularAvailabilities(day, timeInDay)
|
availabilities, err := h.Storage.GetRegularAvailabilities(day, timeInDay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -28,6 +42,11 @@ func (h *Handler) GetDriverJourneys(departure *geojson.Feature, arrival *geojson
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, a := range availabilities {
|
for _, a := range availabilities {
|
||||||
|
// Skip excluded drivers
|
||||||
|
if excludedDrivers[a.DriverId] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if a.Address != nil {
|
if a.Address != nil {
|
||||||
var route *routing.Route
|
var route *routing.Route
|
||||||
if noreturn {
|
if noreturn {
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ func TestHandler_GetDriverJourneys(t *testing.T) {
|
|||||||
Routing: mockRouting,
|
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.NoError(t, err, tt.description)
|
||||||
assert.Len(t, journeys, tt.expectedJourneys, tt.description)
|
assert.Len(t, journeys, tt.expectedJourneys, tt.description)
|
||||||
|
|||||||
@@ -392,14 +392,15 @@ func (*DeleteDriverRegularAvailabilityResponse) Descriptor() ([]byte, []int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetDriverJourneysRequest struct {
|
type GetDriverJourneysRequest struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Departure *GeoJsonFeature `protobuf:"bytes,1,opt,name=departure,proto3" json:"departure,omitempty"`
|
Departure *GeoJsonFeature `protobuf:"bytes,1,opt,name=departure,proto3" json:"departure,omitempty"`
|
||||||
Arrival *GeoJsonFeature `protobuf:"bytes,3,opt,name=arrival,proto3" json:"arrival,omitempty"`
|
Arrival *GeoJsonFeature `protobuf:"bytes,3,opt,name=arrival,proto3" json:"arrival,omitempty"`
|
||||||
DepartureDate *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=departure_date,json=departureDate,proto3" json:"departure_date,omitempty"`
|
DepartureDate *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=departure_date,json=departureDate,proto3" json:"departure_date,omitempty"`
|
||||||
TimeDelta *int64 `protobuf:"varint,6,opt,name=time_delta,json=timeDelta,proto3,oneof" json:"time_delta,omitempty"`
|
TimeDelta *int64 `protobuf:"varint,6,opt,name=time_delta,json=timeDelta,proto3,oneof" json:"time_delta,omitempty"`
|
||||||
Noreturn bool `protobuf:"varint,7,opt,name=noreturn,proto3" json:"noreturn,omitempty"`
|
Noreturn bool `protobuf:"varint,7,opt,name=noreturn,proto3" json:"noreturn,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
ExcludeGroupId *string `protobuf:"bytes,8,opt,name=exclude_group_id,json=excludeGroupId,proto3,oneof" json:"exclude_group_id,omitempty"` // Exclude drivers who have bookings in this group
|
||||||
sizeCache protoimpl.SizeCache
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *GetDriverJourneysRequest) Reset() {
|
func (x *GetDriverJourneysRequest) Reset() {
|
||||||
@@ -467,6 +468,13 @@ func (x *GetDriverJourneysRequest) GetNoreturn() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *GetDriverJourneysRequest) GetExcludeGroupId() string {
|
||||||
|
if x != nil && x.ExcludeGroupId != nil {
|
||||||
|
return *x.ExcludeGroupId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type GetDriverJourneysResponse struct {
|
type GetDriverJourneysResponse struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
DriverJourneys []*SolidarityTransportDriverJourney `protobuf:"bytes,1,rep,name=driver_journeys,json=driverJourneys,proto3" json:"driver_journeys,omitempty"`
|
DriverJourneys []*SolidarityTransportDriverJourney `protobuf:"bytes,1,rep,name=driver_journeys,json=driverJourneys,proto3" json:"driver_journeys,omitempty"`
|
||||||
@@ -1254,15 +1262,17 @@ const file_solidarity_transport_proto_rawDesc = "" +
|
|||||||
"&DeleteDriverRegularAvailabilityRequest\x12\x1b\n" +
|
"&DeleteDriverRegularAvailabilityRequest\x12\x1b\n" +
|
||||||
"\tdriver_id\x18\x01 \x01(\tR\bdriverId\x12'\n" +
|
"\tdriver_id\x18\x01 \x01(\tR\bdriverId\x12'\n" +
|
||||||
"\x0favailability_id\x18\x02 \x01(\tR\x0eavailabilityId\")\n" +
|
"\x0favailability_id\x18\x02 \x01(\tR\x0eavailabilityId\")\n" +
|
||||||
"'DeleteDriverRegularAvailabilityResponse\"\x86\x02\n" +
|
"'DeleteDriverRegularAvailabilityResponse\"\xca\x02\n" +
|
||||||
"\x18GetDriverJourneysRequest\x12-\n" +
|
"\x18GetDriverJourneysRequest\x12-\n" +
|
||||||
"\tdeparture\x18\x01 \x01(\v2\x0f.GeoJsonFeatureR\tdeparture\x12)\n" +
|
"\tdeparture\x18\x01 \x01(\v2\x0f.GeoJsonFeatureR\tdeparture\x12)\n" +
|
||||||
"\aarrival\x18\x03 \x01(\v2\x0f.GeoJsonFeatureR\aarrival\x12A\n" +
|
"\aarrival\x18\x03 \x01(\v2\x0f.GeoJsonFeatureR\aarrival\x12A\n" +
|
||||||
"\x0edeparture_date\x18\x05 \x01(\v2\x1a.google.protobuf.TimestampR\rdepartureDate\x12\"\n" +
|
"\x0edeparture_date\x18\x05 \x01(\v2\x1a.google.protobuf.TimestampR\rdepartureDate\x12\"\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"time_delta\x18\x06 \x01(\x03H\x00R\ttimeDelta\x88\x01\x01\x12\x1a\n" +
|
"time_delta\x18\x06 \x01(\x03H\x00R\ttimeDelta\x88\x01\x01\x12\x1a\n" +
|
||||||
"\bnoreturn\x18\a \x01(\bR\bnoreturnB\r\n" +
|
"\bnoreturn\x18\a \x01(\bR\bnoreturn\x12-\n" +
|
||||||
"\v_time_delta\"g\n" +
|
"\x10exclude_group_id\x18\b \x01(\tH\x01R\x0eexcludeGroupId\x88\x01\x01B\r\n" +
|
||||||
|
"\v_time_deltaB\x13\n" +
|
||||||
|
"\x11_exclude_group_id\"g\n" +
|
||||||
"\x19GetDriverJourneysResponse\x12J\n" +
|
"\x19GetDriverJourneysResponse\x12J\n" +
|
||||||
"\x0fdriver_journeys\x18\x01 \x03(\v2!.SolidarityTransportDriverJourneyR\x0edriverJourneys\"U\n" +
|
"\x0fdriver_journeys\x18\x01 \x03(\v2!.SolidarityTransportDriverJourneyR\x0edriverJourneys\"U\n" +
|
||||||
"\x17GetDriverJourneyRequest\x12\x1b\n" +
|
"\x17GetDriverJourneyRequest\x12\x1b\n" +
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ message GetDriverJourneysRequest {
|
|||||||
google.protobuf.Timestamp departure_date = 5;
|
google.protobuf.Timestamp departure_date = 5;
|
||||||
optional int64 time_delta = 6;
|
optional int64 time_delta = 6;
|
||||||
bool noreturn = 7;
|
bool noreturn = 7;
|
||||||
|
optional string exclude_group_id = 8; // Exclude drivers who have bookings in this group
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetDriverJourneysResponse {
|
message GetDriverJourneysResponse {
|
||||||
|
|||||||
@@ -22,7 +22,12 @@ func (s SolidarityTransportServerImpl) GetDriverJourneys(ctx context.Context, re
|
|||||||
return nil, status.Errorf(codes.Internal, "arrival unmarhsalling error : %v", err)
|
return nil, status.Errorf(codes.Internal, "arrival unmarhsalling error : %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
driverJourneys, err := s.Handler.GetDriverJourneys(departure, arrival, departureDate, req.Noreturn)
|
excludeGroupId := ""
|
||||||
|
if req.ExcludeGroupId != nil {
|
||||||
|
excludeGroupId = *req.ExcludeGroupId
|
||||||
|
}
|
||||||
|
|
||||||
|
driverJourneys, err := s.Handler.GetDriverJourneys(departure, arrival, departureDate, req.Noreturn, excludeGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("issue in GetDriverJourneys handler")
|
log.Error().Err(err).Msg("issue in GetDriverJourneys handler")
|
||||||
return nil, status.Errorf(codes.Internal, "could not get driver journeys : %v", err)
|
return nil, status.Errorf(codes.Internal, "could not get driver journeys : %v", err)
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ func (s MongoDBStorage) UpdateBookingStatus(bookingid string, newStatus string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s MongoDBStorage) GetBookingsByGroupId(groupId string) ([]*types.Booking, error) {
|
func (s MongoDBStorage) GetBookingsByGroupId(groupId string) ([]*types.Booking, error) {
|
||||||
filter := bson.M{"groupid": groupId}
|
filter := bson.M{"group_id": groupId}
|
||||||
|
|
||||||
cursor, err := s.Collections.Bookings.Find(context.Background(), filter)
|
cursor, err := s.Collections.Bookings.Find(context.Background(), filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user