chore: fix prices

This commit is contained in:
2026-03-02 03:28:45 +01:00
parent e7a6dc2230
commit 6c8af9acd4
10 changed files with 266 additions and 41 deletions
+48 -1
View File
@@ -1,9 +1,11 @@
package db
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
)
@@ -21,12 +23,57 @@ func (d *Database) NotifyClient(username string, commandID int, notifType, messa
notifJSON, _ := json.Marshal(notification)
Redis.LPush(RedisCtx, notifKey, notifJSON)
Redis.Expire(RedisCtx, notifKey, 7*24*time.Hour) // Expire après 7 jours
Redis.Expire(RedisCtx, notifKey, 7*24*time.Hour)
// Envoyer push notification si le client a un token enregistré
pushToken, err := d.GetClientPushToken(username)
if err == nil && pushToken != "" {
go sendExpoPush(pushToken, "Uber Stup", message, commandID, notifType)
}
log.Printf("📬 Notification envoyée à %s: %s", username, message)
return nil
}
func sendExpoPush(token, title, body string, commandID int, notifType string) {
payload := map[string]interface{}{
"to": token,
"title": title,
"body": body,
"channelId": "orders",
"data": map[string]interface{}{
"command_id": commandID,
"type": notifType,
},
"sound": "default",
}
jsonBody, err := json.Marshal(payload)
if err != nil {
log.Printf("❌ [EXPO_PUSH] Erreur marshal: %v", err)
return
}
req, err := http.NewRequest("POST", "https://exp.host/--/api/v2/push/send", bytes.NewBuffer(jsonBody))
if err != nil {
log.Printf("❌ [EXPO_PUSH] Erreur création requête: %v", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Accept-Encoding", "gzip, deflate")
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
log.Printf("❌ [EXPO_PUSH] Erreur envoi: %v", err)
return
}
defer resp.Body.Close()
log.Printf("✅ [EXPO_PUSH] Push envoyé à %s (status: %d)", token, resp.StatusCode)
}
// AddDeliveryRating ajoute une note pour un livreur
func (d *Database) AddDeliveryRating(livreurUsername string, commandID, rating int, comment string) error {
query := `