fix: update history count

This commit is contained in:
Arnaud Delcasse
2026-02-25 10:05:07 +01:00
parent b5e722ff9b
commit 1b1c4443fc
7 changed files with 71 additions and 13 deletions

View File

@@ -254,11 +254,11 @@ func ReadConfig() (*viper.Viper, error) {
"geo": map[string]any{
"type": "addok", // Options: "pelias", "addok"
"pelias": map[string]any{
"url": "https://geocode.ridygo.fr",
"url": "http://57.128.110.46:4000/V1",
"autocomplete": "/autocomplete?text=",
},
"addok": map[string]any{
"url": "https://api-adresse.data.gouv.fr",
"url": "https://data.geopf.fr/geocodage/",
"autocomplete": "/search/?q=",
},
},

View File

@@ -36,6 +36,8 @@ 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
@@ -46,6 +48,7 @@ type SearchJourneyOptions struct {
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
}

View File

@@ -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

View File

@@ -36,7 +36,7 @@ func (s BeneficiariesCovoiturage) JSONWithLimits(a int, b int) template.JS {
return s.JSON()
}
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools []*geojson.FeatureCollection, transitjourneys any, vehicles any, searched bool, departure any, destination any, departuredate string, departuretime string, driverJourneys any, solidarityDrivers any, organizedCarpools any, beneficiaries any, kbData any, passengerid string, savedSearches any, beneficiariesMap any) {
func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request, carpools []*geojson.FeatureCollection, transitjourneys any, vehicles any, searched bool, departure any, destination any, departuredate string, departuretime string, departuredatetime any, driverJourneys any, solidarityDrivers any, organizedCarpools any, beneficiaries any, kbData any, passengerid string, savedSearches any, beneficiariesMap any, driverLastTrips any, lastTripDays int) {
files := renderer.ThemeConfig.GetStringSlice("views.journeys.search.files")
state := NewState(r, renderer.ThemeConfig, journeysMenu)
journeyTabs := renderer.ThemeConfig.Get("journey_tabs")
@@ -44,6 +44,7 @@ func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request,
"searched": searched,
"departuredate": departuredate,
"departuretime": departuretime,
"departuredatetime": departuredatetime,
"departure": departure,
"destination": destination,
"journeys": transitjourneys,
@@ -52,6 +53,8 @@ func (renderer *Renderer) JourneysSearch(w http.ResponseWriter, r *http.Request,
"vehicles": vehicles,
"driver_journeys": driverJourneys,
"solidarity_drivers": solidarityDrivers,
"driver_last_trips": driverLastTrips,
"last_trip_days": lastTripDays,
"querystring": r.URL.RawQuery,
"beneficiaries": beneficiariesMap,
"beneficiaries_list": beneficiaries,

View File

@@ -109,7 +109,7 @@ func (renderer *Renderer) SolidarityTransportDriverJourney(w http.ResponseWriter
renderer.Render("solidarity transport driver creation", w, r, files, state)
}
func (renderer *Renderer) SolidarityTransportBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, driver any, passenger any, passengerWalletBalance float64, replacementDrivers any, replacementDriversMap any, replacementPricing any, replacementLocations any) {
func (renderer *Renderer) SolidarityTransportBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, driver any, passenger any, passengerWalletBalance float64, replacementDrivers any, replacementDriversMap any, replacementPricing any, replacementLocations any, driverLastTrips any, lastTripDays int) {
files := renderer.ThemeConfig.GetStringSlice("views.solidarity_transport.booking_display.files")
bookingMotivations := renderer.GlobalConfig.Get("modules.solidarity_transport.booking_motivations")
state := NewState(r, renderer.ThemeConfig, solidarityTransportMenu)
@@ -124,6 +124,8 @@ func (renderer *Renderer) SolidarityTransportBookingDisplay(w http.ResponseWrite
"replacement_drivers_map": replacementDriversMap,
"replacement_pricing": replacementPricing,
"replacement_locations": replacementLocations,
"driver_last_trips": driverLastTrips,
"last_trip_days": lastTripDays,
}
renderer.Render("booking display", w, r, files, state)

View File

@@ -159,6 +159,7 @@ func (h *Handler) JourneysSearchHTTPHandler() http.HandlerFunc {
destinationGeo,
departureDate,
departureTime,
departureDateTime,
result.DriverJourneys,
result.Drivers,
result.OrganizedCarpools,
@@ -167,6 +168,8 @@ func (h *Handler) JourneysSearchHTTPHandler() http.HandlerFunc {
passengerID,
savedSearches,
beneficiariesMap,
result.DriverLastTrips,
result.LastTripDays,
)
}
}

View File

@@ -9,6 +9,7 @@ import (
"strings"
"time"
coreapplication "git.coopgo.io/coopgo-apps/parcoursmob/core/application"
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
@@ -614,12 +615,17 @@ func (h *Handler) SolidarityTransportBookingDisplayHTTPHandler() http.HandlerFun
var replacementDriversMap map[string]mobilityaccountsstorage.Account
var replacementPricing map[string]map[string]interface{}
var replacementLocations map[string]string
var driverLastTrips map[string]time.Time
var lastTripDays int
if result.Booking.Status == "CANCELLED" {
// Initialize maps to avoid nil pointer in template
replacementDriversMap = make(map[string]mobilityaccountsstorage.Account)
replacementPricing = make(map[string]map[string]interface{})
replacementLocations = make(map[string]string)
driverLastTrips = make(map[string]time.Time)
// Preserve the original booking's noreturn status when searching for replacement drivers
noreturn := result.Booking.Journey.Noreturn
searchResult, err := h.applicationHandler.SearchJourneys(
r.Context(),
result.Booking.Journey.PassengerPickupDate,
@@ -628,11 +634,15 @@ func (h *Handler) SolidarityTransportBookingDisplayHTTPHandler() http.HandlerFun
result.Booking.PassengerId,
result.Booking.DriverId, // Exclude the original driver
result.Booking.GroupId, // Exclude drivers with bookings in this group
nil, // options - use defaults
&coreapplication.SearchJourneyOptions{
SolidarityTransportNoreturn: &noreturn,
},
)
if err == nil {
replacementDrivers = searchResult.DriverJourneys
replacementDriversMap = searchResult.Drivers
driverLastTrips = searchResult.DriverLastTrips
lastTripDays = searchResult.LastTripDays
// Calculate pricing for each replacement driver journey
for _, dj := range searchResult.DriverJourneys {
@@ -668,7 +678,7 @@ func (h *Handler) SolidarityTransportBookingDisplayHTTPHandler() http.HandlerFun
}
}
h.renderer.SolidarityTransportBookingDisplay(w, r, result.Booking, result.Driver, result.Passenger, result.PassengerWalletBalance, replacementDrivers, replacementDriversMap, replacementPricing, replacementLocations)
h.renderer.SolidarityTransportBookingDisplay(w, r, result.Booking, result.Driver, result.Passenger, result.PassengerWalletBalance, replacementDrivers, replacementDriversMap, replacementPricing, replacementLocations, driverLastTrips, lastTripDays)
}
}