chore: refacto
This commit is contained in:
@@ -81,7 +81,7 @@ func UpdateCommandAddress(c *gin.Context) {
|
||||
// ✅ Récupération sécurisée du username
|
||||
adminUsername, err := safeGetUsername(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Non authentifié"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func ProposeAddressChange(c *gin.Context) {
|
||||
|
||||
staffUsername, err := safeGetUsername(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Non authentifié"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -198,15 +198,14 @@ func ProposeAddressChange(c *gin.Context) {
|
||||
}
|
||||
|
||||
if err := database.ProposeAddressChange(commandID, req.ProposedAddress, staffUsername); err != nil {
|
||||
log.Printf("❌ [PROPOSE_ADDR] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
utils.ServerErr(c, "Impossible de proposer l'adresse", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Notifier le client
|
||||
clientUsername, _ := command["username"].(string)
|
||||
if clientUsername != "" {
|
||||
msg := fmt.Sprintf("📍 Une nouvelle adresse de livraison vous est proposée pour la commande #%d : %s. Veuillez l'accepter ou la refuser dans le suivi de commande.", commandID, req.ProposedAddress)
|
||||
msg := fmt.Sprintf("📍 Une nouvelle adresse de livraison vous est proposée pour votre commande #%d : %s. Veuillez l'accepter ou la refuser dans le suivi de commande.", database.GetClientOrderID(commandID), req.ProposedAddress)
|
||||
database.NotifyClient(clientUsername, commandID, "address_proposal", msg)
|
||||
}
|
||||
|
||||
@@ -248,8 +247,7 @@ func RespondToAddressProposal(c *gin.Context) {
|
||||
}
|
||||
|
||||
if err := database.RespondToAddressProposal(commandID, clientUsername, req.Accepted); err != nil {
|
||||
log.Printf("❌ [RESPOND_ADDR] Erreur: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
utils.ServerErr(c, "Impossible de traiter la réponse", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -296,7 +294,6 @@ func GetAllCommands(c *gin.Context) {
|
||||
log.Printf("❌ [GET_CMDS] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Erreur lors de la récupération des commandes",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -444,7 +441,7 @@ func StaffApproveDelivery(c *gin.Context) {
|
||||
totalPoints, pointCategory, clientUsername, err := database.ApproveDeliveryAtomicByStaff(commandID, staffUsername)
|
||||
if err != nil {
|
||||
log.Printf("❌ [STAFF_APPROVE] Erreur: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Impossible de confirmer la réception: " + err.Error()})
|
||||
utils.ServerErr(c, "Impossible de confirmer la réception", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -474,7 +471,7 @@ func ValidateDelivery(c *gin.Context) {
|
||||
|
||||
adminUsername, err := safeGetUsername(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Non authentifié"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -604,7 +601,6 @@ func GetAvailableDeliveryPersons(c *gin.Context) {
|
||||
log.Printf("❌ [GET_LIVREURS] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Erreur lors de la récupération des livreurs",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -651,7 +647,6 @@ func AssignDeliveryPerson(c *gin.Context) {
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Données invalides",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -665,7 +660,6 @@ func AssignDeliveryPerson(c *gin.Context) {
|
||||
log.Printf("❌ [ASSIGN] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Erreur assignation livreur",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -704,7 +698,6 @@ func GetClientCommandsHistory(c *gin.Context) {
|
||||
log.Printf("❌ [HISTORY] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Erreur récupération historique",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -805,7 +798,7 @@ func NotifyClientToDescend(c *gin.Context) {
|
||||
}
|
||||
|
||||
staffUsername, _ := c.Get("username")
|
||||
msg := fmt.Sprintf("Votre commande #%d est prête ! Vous pouvez descendre la récupérer.", commandID)
|
||||
msg := fmt.Sprintf("Votre commande #%d est prête ! Vous pouvez descendre la récupérer.", database.GetClientOrderID(commandID))
|
||||
database.NotifyClient(clientUsername, commandID, "ready_pickup", msg)
|
||||
database.AddCommandLog(commandID, "notification", fmt.Sprintf("Client notifié de descendre par %s", staffUsername), staffUsername.(string))
|
||||
|
||||
@@ -859,7 +852,6 @@ func ShowItems(c *gin.Context) {
|
||||
log.Printf("❌ [ITEMS] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Erreur lors de la récupération des items",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -951,7 +943,6 @@ func GetCommandItemsWithDetails(c *gin.Context) {
|
||||
log.Printf("❌ [ITEMS_DETAILED] Erreur DB: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Erreur récupération items",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -964,12 +955,13 @@ func GetCommandItemsWithDetails(c *gin.Context) {
|
||||
}
|
||||
|
||||
commandInfo := map[string]interface{}{
|
||||
"id": items[0]["command_id"],
|
||||
"command_status": items[0]["command_status"],
|
||||
"command_address": items[0]["command_address"],
|
||||
"total_prix": items[0]["total_prix"],
|
||||
"livreur_assign": items[0]["livreur_assign"],
|
||||
"command_created_at": items[0]["command_created_at"],
|
||||
"id": items[0]["command_id"],
|
||||
"command_status": items[0]["command_status"],
|
||||
"command_address": items[0]["command_address"],
|
||||
"total_prix": items[0]["total_prix"],
|
||||
"livreur_assign": items[0]["livreur_assign"],
|
||||
"command_created_at": items[0]["command_created_at"],
|
||||
"client_order_number": items[0]["client_order_number"],
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@@ -1007,7 +999,6 @@ func UpdateItemStatus(c *gin.Context) {
|
||||
log.Printf("❌ [UPD_ITEM] Erreur JSON: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Status requis",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -1038,7 +1029,6 @@ func UpdateItemStatus(c *gin.Context) {
|
||||
log.Printf("❌ [UPD_ITEM] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Erreur lors de la mise à jour",
|
||||
"details": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -1065,7 +1055,7 @@ func DeleteCommandItem(c *gin.Context) {
|
||||
|
||||
adminUsername, err := safeGetUsername(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Non authentifié"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1084,8 +1074,7 @@ func DeleteCommandItem(c *gin.Context) {
|
||||
log.Printf("🗑️ [DEL_ITEM] Admin %s supprime item %d de cmd %d", adminUsername, itemID, commandID)
|
||||
|
||||
if err := database.DeleteCommandItem(commandID, itemID); err != nil {
|
||||
log.Printf("❌ [DEL_ITEM] Erreur: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
utils.ServerErr(c, "Impossible de supprimer l'item", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1137,8 +1126,7 @@ func UpdateCommandStatusAdmin(c *gin.Context) {
|
||||
}
|
||||
|
||||
if err := database.UpdateCommandStatus(commandID, req.Status); err != nil {
|
||||
log.Printf("❌ [STATUS_ADMIN] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
utils.ServerErr(c, "Impossible de mettre à jour le statut", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user