chore: update

This commit is contained in:
2026-03-19 19:56:51 +01:00
parent 3384ebded0
commit 7173266bb9
31 changed files with 3645 additions and 1942 deletions
+42
View File
@@ -172,6 +172,48 @@ func (d *Database) NotifyAllAdminCabine(commandID int, clientUsername, deliveryA
log.Printf("📬 [ADMIN_NOTIF] Notif Redis + push (%d tokens) pour commande #%d", sent, commandID)
}
// NotifyAllAdminCabineAlert envoie une notification Redis + push à tous les admins/cabines
// lors du déclenchement d'une alerte par un livreur.
func (d *Database) NotifyAllAdminCabineAlert(alertID int, livreurUsername, alertMessage string) {
rows, err := d.Query(
`SELECT username, COALESCE(push_token, '') FROM users WHERE role IN ('admin','cabine')`,
)
if err != nil {
log.Printf("❌ [ALERT_NOTIF] Erreur lecture users admin/cabine: %v", err)
return
}
defer rows.Close()
title := "🚨 Alerte livreur"
body := fmt.Sprintf("%s — livreur : %s", alertMessage, livreurUsername)
notification := map[string]interface{}{
"alert_id": alertID,
"type": "alert",
"message": body,
"created_at": time.Now().Format(time.RFC3339),
"read": false,
}
notifJSON, _ := json.Marshal(notification)
sent := 0
for rows.Next() {
var username, token string
if err := rows.Scan(&username, &token); err != nil {
continue
}
notifKey := fmt.Sprintf("notifications:%s", username)
Redis.LPush(RedisCtx, notifKey, notifJSON)
Redis.Expire(RedisCtx, notifKey, 7*24*time.Hour)
if token != "" {
go sendExpoPushWithChannel(token, title, body, alertID, "alert", "orders")
sent++
}
}
log.Printf("🚨 [ALERT_NOTIF] Notif Redis + push (%d tokens) pour alerte #%d de %s", sent, alertID, livreurUsername)
}
// AddDeliveryRating ajoute une note pour un livreur
func (d *Database) AddDeliveryRating(livreurUsername string, commandID, rating int, comment string) error {
query := `