chore: build
This commit is contained in:
@@ -3,8 +3,10 @@ package handlers
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gestion/db"
|
||||
"gestion/services"
|
||||
"gestion/utils"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -149,6 +151,7 @@ func UpdateCommandAddress(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// ProposeAddressChange propose une nouvelle adresse au client pour validation
|
||||
func ProposeAddressChange(c *gin.Context) {
|
||||
database := c.MustGet("database").(*db.Database)
|
||||
|
||||
@@ -629,6 +632,7 @@ func GetAvailableDeliveryPersons(c *gin.Context) {
|
||||
// Cabine: POST /api/v1/cabine/commands/:id/assign (body: {"livreur_username": "..."})
|
||||
func AssignDeliveryPerson(c *gin.Context) {
|
||||
database := c.MustGet("database").(*db.Database)
|
||||
geoService := c.MustGet("geoService").(*services.GeoService)
|
||||
|
||||
// ✅ SÉCURITÉ: Admin ou Cabine
|
||||
role := c.GetString("role")
|
||||
@@ -678,6 +682,39 @@ func AssignDeliveryPerson(c *gin.Context) {
|
||||
fmt.Sprintf("Livreur '%s' assigné manuellement par %s", livreurUsername, staffUsername),
|
||||
staffUsername.(string))
|
||||
|
||||
// Géocodage async : stocker les coords si absentes
|
||||
go func() {
|
||||
cmd, err := database.GetCommandByID(commandID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
dLat, _ := cmd["dest_latitude"].(float64)
|
||||
dLon, _ := cmd["dest_longitude"].(float64)
|
||||
if dLat != 0 && dLon != 0 {
|
||||
return // coords déjà présentes
|
||||
}
|
||||
adresse, _ := cmd["adresse"].(string)
|
||||
if adresse == "" {
|
||||
return
|
||||
}
|
||||
location, err := geoService.GeocodeAddress(adresse)
|
||||
if err != nil || location == nil {
|
||||
log.Printf("⚠️ [ASSIGN] Géocodage échoué pour cmd %d: %v", commandID, err)
|
||||
return
|
||||
}
|
||||
coordsJSON, _ := json.Marshal(map[string]float64{
|
||||
"lat": location.Latitude,
|
||||
"lon": location.Longitude,
|
||||
})
|
||||
destKey := fmt.Sprintf("command:destination:%d", commandID)
|
||||
db.Redis.Set(db.RedisCtx, destKey, coordsJSON, 4*time.Hour)
|
||||
database.GDB.Exec(
|
||||
"UPDATE commandes SET dest_latitude = ?, dest_longitude = ? WHERE id = ?",
|
||||
location.Latitude, location.Longitude, commandID,
|
||||
)
|
||||
log.Printf("📍 [ASSIGN] Coords stockées pour cmd %d: (%.6f, %.6f)", commandID, location.Latitude, location.Longitude)
|
||||
}()
|
||||
|
||||
log.Printf("✅ [ASSIGN] Commande %d assignée à %s", commandID, livreurUsername)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
||||
Reference in New Issue
Block a user