fix: manage quantity && update geoloca

This commit is contained in:
2026-05-12 19:35:02 +02:00
parent 1319a4219a
commit 9a2f0d91ad
7 changed files with 815 additions and 42 deletions
+27 -9
View File
@@ -1,7 +1,3 @@
// ============================================
// handlers/geo_handlers.go - VERSION CORRIGÉE COMPLÈTE
// ============================================
package handlers
import (
@@ -20,6 +16,7 @@ import (
// ============================================
// GÉOCODAGE D'ADRESSES
// ============================================
// geo_handlers.go
func GeocodeAddress(c *gin.Context) {
geoService := c.MustGet("geoService").(*services.GeoService)
@@ -34,19 +31,40 @@ func GeocodeAddress(c *gin.Context) {
location, err := geoService.GeocodeAddress(req.Address)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Impossible de géocoder cette adresse"})
// Tentative de correction — resolveAddress ne touche pas à c.JSON
suggestion, err := resolveAddress(geoService, req.Address)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Adresse introuvable, vérifiez l'orthographe"})
return
}
log.Printf("✅ Adresse corrigée: '%s' → '%s' (confiance %.0f%%)",
req.Address, suggestion.CorrectedAddress, suggestion.Confidence*100)
c.JSON(http.StatusOK, gin.H{
"success": true,
"latitude": suggestion.Coordinates.Latitude,
"longitude": suggestion.Coordinates.Longitude,
"display_name": suggestion.CorrectedAddress,
"correction_applied": suggestion.CorrectionApplied,
"confidence": suggestion.Confidence,
})
return
}
log.Printf("📍 Adresse géocodée: %s -> (%.6f, %.6f)", req.Address, location.Latitude, location.Longitude)
c.JSON(http.StatusOK, gin.H{
"success": true,
"latitude": location.Latitude,
"longitude": location.Longitude,
"display_name": location.DisplayName,
"success": true,
"latitude": location.Latitude,
"longitude": location.Longitude,
"display_name": location.DisplayName,
"correction_applied": false,
})
}
// resolveAddress : logique pure, sans toucher à gin.Context
func resolveAddress(geoService *services.GeoService, address string) (*services.AddressSuggestion, error) {
return geoService.CorrectionService().ResolveAddress(address)
}
// FindNearestDeliveryPerson trouve le livreur le plus proche d'une adresse
func FindNearestDeliveryPerson(c *gin.Context) {
database := c.MustGet("database").(*db.Database)