fix: update history count
This commit is contained in:
@@ -36,16 +36,19 @@ type SearchJourneysResult struct {
|
||||
Drivers map[string]mobilityaccountsstorage.Account
|
||||
OrganizedCarpools []*carpoolproto.CarpoolServiceDriverJourney
|
||||
KnowledgeBaseResults []any
|
||||
DriverLastTrips map[string]time.Time // Map of driver ID to their last completed trip date
|
||||
LastTripDays int // Number of days to look back for last trips
|
||||
}
|
||||
|
||||
// SearchJourneyOptions contains per-request options for journey search
|
||||
type SearchJourneyOptions struct {
|
||||
DisableSolidarityTransport bool
|
||||
DisableOrganizedCarpool bool
|
||||
DisableCarpoolOperators bool
|
||||
DisableTransit bool
|
||||
DisableFleetVehicles bool
|
||||
DisableKnowledgeBase bool
|
||||
DisableSolidarityTransport bool
|
||||
DisableOrganizedCarpool bool
|
||||
DisableCarpoolOperators bool
|
||||
DisableTransit bool
|
||||
DisableFleetVehicles bool
|
||||
DisableKnowledgeBase bool
|
||||
SolidarityTransportNoreturn *bool
|
||||
}
|
||||
|
||||
// SearchJourneys performs the business logic for journey search
|
||||
@@ -111,6 +114,10 @@ func (h *ApplicationHandler) SearchJourneys(
|
||||
if solidarityExcludeGroupId != "" {
|
||||
req.ExcludeGroupId = &solidarityExcludeGroupId
|
||||
}
|
||||
// Pass noreturn to filter journeys by type (one-way vs round-trip)
|
||||
if options.SolidarityTransportNoreturn != nil {
|
||||
req.Noreturn = *options.SolidarityTransportNoreturn
|
||||
}
|
||||
|
||||
res, err := h.services.GRPC.SolidarityTransport.GetDriverJourneys(ctx, req)
|
||||
if err != nil {
|
||||
@@ -291,6 +298,33 @@ func (h *ApplicationHandler) SearchJourneys(
|
||||
}
|
||||
}
|
||||
|
||||
// Get last trip dates for solidarity transport drivers
|
||||
driverLastTrips := make(map[string]time.Time)
|
||||
lastTripDays := h.config.GetInt("modules.journeys.solutions.solidarity_transport.last_trip_days")
|
||||
if lastTripDays <= 0 {
|
||||
lastTripDays = 15
|
||||
}
|
||||
if len(solidarityTransportResults) > 0 {
|
||||
// Get all validated bookings from the past N days to find last trips
|
||||
bookingsRequest := &gen.GetSolidarityTransportBookingsRequest{
|
||||
StartDate: timestamppb.New(departureDateTime.Add(-time.Duration(lastTripDays) * 24 * time.Hour)),
|
||||
EndDate: timestamppb.New(departureDateTime.Add(24 * time.Hour)),
|
||||
Status: "VALIDATED",
|
||||
}
|
||||
bookingsResp, err := h.services.GRPC.SolidarityTransport.GetSolidarityTransportBookings(ctx, bookingsRequest)
|
||||
if err == nil {
|
||||
for _, booking := range bookingsResp.Bookings {
|
||||
if booking.Journey != nil {
|
||||
tripDate := booking.Journey.PassengerPickupDate.AsTime()
|
||||
// Only consider trips that have already happened
|
||||
if lastTrip, exists := driverLastTrips[booking.DriverId]; !exists || tripDate.After(lastTrip) {
|
||||
driverLastTrips[booking.DriverId] = tripDate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &SearchJourneysResult{
|
||||
CarpoolResults: carpoolResults,
|
||||
TransitResults: transitResults,
|
||||
@@ -300,6 +334,8 @@ func (h *ApplicationHandler) SearchJourneys(
|
||||
Drivers: drivers,
|
||||
OrganizedCarpools: organizedCarpoolResults,
|
||||
KnowledgeBaseResults: knowledgeBaseResults,
|
||||
DriverLastTrips: driverLastTrips,
|
||||
LastTripDays: lastTripDays,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1391,7 +1391,11 @@ func (h *ApplicationHandler) calculateSolidarityTransportPricing(ctx context.Con
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
history = history + len(solidarity.Bookings)
|
||||
for _, booking := range solidarity.Bookings {
|
||||
if booking.Status == "VALIDATED" || booking.Status == "WAITING_CONFIRMATION" {
|
||||
history++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var passengerGeo pricing.GeographyParams
|
||||
|
||||
Reference in New Issue
Block a user