40 lines
991 B
Go
40 lines
991 B
Go
package db
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
// PublishCommandEvent publie un événement de commande
|
|
func (d *Database) PublishCommandEvent(commandID int, eventType, message string) {
|
|
channel := fmt.Sprintf("events:command:%d", commandID)
|
|
|
|
event := map[string]any{
|
|
"command_id": commandID,
|
|
"type": eventType,
|
|
"message": message,
|
|
"timestamp": time.Now().Unix(),
|
|
}
|
|
|
|
data, _ := json.Marshal(event)
|
|
Redis.Publish(RedisCtx, channel, data)
|
|
}
|
|
|
|
// PublishDeliveryPersonLocationUpdate publie un événement de mise à jour de position
|
|
func (d *Database) PublishDeliveryPersonLocationUpdate(username string, lat, lon float64) {
|
|
message := map[string]any{
|
|
"type": "location_update",
|
|
"username": username,
|
|
"latitude": lat,
|
|
"longitude": lon,
|
|
"timestamp": time.Now().Unix(),
|
|
}
|
|
|
|
data, _ := json.Marshal(message)
|
|
Redis.Publish(RedisCtx, "delivery:events", data)
|
|
|
|
log.Printf("📡 Événement publié: Position de %s mise à jour", username)
|
|
}
|