chore: add clock middleware
This commit is contained in:
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user