chore: refacto
This commit is contained in:
@@ -19,10 +19,6 @@ var allowedStatuses = map[string]bool{
|
||||
"busy": true,
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 📊 STATISTIQUES LIVREUR
|
||||
// ============================================
|
||||
|
||||
// CountDeliveriesByStatus compte les livraisons d'un livreur par statut
|
||||
func (d *Database) CountDeliveriesByStatus(livreurUsername string, statuses string) (int, error) {
|
||||
if statuses == "" {
|
||||
@@ -231,17 +227,6 @@ func (d *Database) GetDeliveryPersonHistory(livreurUsername string, limit, offse
|
||||
return history, nil
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 📍 GESTION POSITION GPS
|
||||
// ============================================
|
||||
// ⚠️ REMARQUE: Les fonctions UpdateDeliveryPersonLocation et GetDeliveryPersonLocation
|
||||
// sont déjà définies dans db/delivery_db.go
|
||||
// Nous réutilisons ces fonctions existantes au lieu de les redéfinir ici
|
||||
|
||||
// ============================================
|
||||
// 🔄 GESTION STATUT LIVREUR
|
||||
// ============================================
|
||||
|
||||
// GetDeliveryPersonStatus récupère le statut d'un livreur
|
||||
func (d *Database) GetDeliveryPersonStatus(livreurUsername string) (string, error) {
|
||||
statusKey := fmt.Sprintf("delivery:status:%s", livreurUsername)
|
||||
@@ -277,10 +262,6 @@ func (d *Database) UpdateDeliveryPersonStatus(livreurUsername string, status str
|
||||
return nil
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 📦 GESTION QUEUE LIVREUR
|
||||
// ============================================
|
||||
|
||||
// GetDeliverymanQueueSize récupère la taille de la queue d'un livreur
|
||||
func (d *Database) GetDeliverymanQueueSize(livreurUsername string) (int, error) {
|
||||
queueKey := fmt.Sprintf("delivery:queue:%s", livreurUsername)
|
||||
@@ -312,10 +293,6 @@ func (d *Database) GetDeliverymanQueue(livreurUsername string) ([]int, error) {
|
||||
return queue, nil
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 🔧 FONCTIONS UTILITAIRES
|
||||
// ============================================
|
||||
|
||||
// UpdateCommandLivreur met à jour le livreur assigné à une commande
|
||||
func (d *Database) UpdateCommandLivreur(commandID int, livreurUsername string) error {
|
||||
query := `UPDATE commandes
|
||||
@@ -338,19 +315,15 @@ func (d *Database) UpdateCommandLivreur(commandID int, livreurUsername string) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 📊 STATISTIQUES SYSTÈME
|
||||
// ============================================
|
||||
|
||||
// GetAllDeliveryPersonsStats récupère les stats de tous les livreurs
|
||||
func (d *Database) GetAllDeliveryPersonsStats() ([]map[string]interface{}, error) {
|
||||
func (d *Database) GetAllDeliveryPersonsStats() ([]map[string]any, error) {
|
||||
// Récupérer tous les livreurs
|
||||
livreurs, err := d.GetAvailableDeliveryPersons()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("erreur récupération livreurs: %w", err)
|
||||
}
|
||||
|
||||
var stats []map[string]interface{}
|
||||
var stats []map[string]any
|
||||
|
||||
for _, livreur := range livreurs {
|
||||
username := livreur["username"].(string)
|
||||
@@ -361,7 +334,7 @@ func (d *Database) GetAllDeliveryPersonsStats() ([]map[string]interface{}, error
|
||||
queueSize, _ := d.GetDeliverymanQueueSize(username)
|
||||
status, _ := d.GetDeliveryPersonStatus(username)
|
||||
|
||||
statEntry := map[string]interface{}{
|
||||
statEntry := map[string]any{
|
||||
"username": username,
|
||||
"total_deliveries": totalDeliveries,
|
||||
"completed_deliveries": completedDeliveries,
|
||||
@@ -375,10 +348,6 @@ func (d *Database) GetAllDeliveryPersonsStats() ([]map[string]interface{}, error
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 🔍 RECHERCHE & FILTRAGE
|
||||
// ============================================
|
||||
|
||||
// GetDeliveryPersonsByStatus récupère les livreurs par statut
|
||||
func (d *Database) GetDeliveryPersonsByStatus(status string) ([]string, error) {
|
||||
// Récupérer tous les livreurs
|
||||
@@ -411,10 +380,6 @@ func (d *Database) GetAvailableDeliveryPersonsCount() (int, error) {
|
||||
return len(availableLivreurs), nil
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 🗑️ SUPPRESSION & NETTOYAGE
|
||||
// ============================================
|
||||
|
||||
// ClearDeliveryPersonData supprime toutes les données d'un livreur (admin uniquement)
|
||||
func (d *Database) ClearDeliveryPersonData(livreurUsername string) error {
|
||||
log.Printf("🗑️ [ClearDeliveryData] Nettoyage données pour: %s", livreurUsername)
|
||||
|
||||
Reference in New Issue
Block a user