chore: add clock middleware

This commit is contained in:
2026-02-28 13:28:46 +01:00
parent f91d4276cc
commit 1f332643a2
5 changed files with 67 additions and 10 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ func main() {
// Configuration CORS
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"https://uber-stup.club"},
AllowOrigins: []string{"https://uber-stup.club", "http://localhost:5173"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
@@ -0,0 +1,37 @@
package middleware
import (
"log"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
// OrderHoursMiddleware bloque les commandes en dehors de la plage 13h55 - 23h30.
func OrderHoursMiddleware(c *gin.Context) {
now := time.Now()
hour := now.Hour()
min := now.Minute()
// Convertir l'heure courante en minutes depuis minuit pour faciliter la comparaison
currentMinutes := hour*60 + min
openMinutes := 13*60 + 55 // 13h55
closeMinutes := 23*60 + 30 // 23h30
if currentMinutes < openMinutes || currentMinutes >= closeMinutes {
log.Printf("❌ [CLOCK-MWARE] Commande refusée à %02d:%02d (plage autorisée: 13h55 - 23h30)", hour, min)
c.JSON(http.StatusForbidden, gin.H{
"error": "Commandes non disponibles à cette heure",
"message": "Vous pouvez commander entre 13h55 et 23h30",
"current_time": now.Format("15:04"),
"open_at": "13:55",
"close_at": "23:30",
})
c.Abort()
return
}
log.Printf("✅ [CLOCK-MWARE] Commande autorisée à %02d:%02d", hour, min)
c.Next()
}
+2 -2
View File
@@ -61,8 +61,8 @@ func SetupRoutes(router *gin.Engine, database *db.Database, geoService *services
cartGroupV1.DELETE("/panier/clear", handlers.ClearBasket) // ✅ CORRIGÉ - Sans :username
// Commandes
cartGroupV1.POST("/checkout", handlers.ValidateBasket) // ✅ Auto-assign GPS
cartGroupV1.GET("/my-commands", handlers.GetMyCommandsWithTracking) // ✅ Avec suivi
cartGroupV1.POST("/checkout", middleware.OrderHoursMiddleware, handlers.ValidateBasket) // ✅ Auto-assign GPS
cartGroupV1.GET("/my-commands", handlers.GetMyCommandsWithTracking) // ✅ Avec suivi
// ⭐ NOUVEAUX - SUIVI CLIENT TEMPS RÉEL
cartGroupV1.GET("/commands/:id/eta", handlers.GetOrderETA) // ✅ AJOUTÉ