chore: add clock middleware
This commit is contained in:
@@ -96,7 +96,7 @@ func main() {
|
|||||||
|
|
||||||
// Configuration CORS
|
// Configuration CORS
|
||||||
r.Use(cors.New(cors.Config{
|
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"},
|
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||||
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
|
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
|
||||||
ExposeHeaders: []string{"Content-Length"},
|
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()
|
||||||
|
}
|
||||||
@@ -61,8 +61,8 @@ func SetupRoutes(router *gin.Engine, database *db.Database, geoService *services
|
|||||||
cartGroupV1.DELETE("/panier/clear", handlers.ClearBasket) // ✅ CORRIGÉ - Sans :username
|
cartGroupV1.DELETE("/panier/clear", handlers.ClearBasket) // ✅ CORRIGÉ - Sans :username
|
||||||
|
|
||||||
// Commandes
|
// Commandes
|
||||||
cartGroupV1.POST("/checkout", handlers.ValidateBasket) // ✅ Auto-assign GPS
|
cartGroupV1.POST("/checkout", middleware.OrderHoursMiddleware, handlers.ValidateBasket) // ✅ Auto-assign GPS
|
||||||
cartGroupV1.GET("/my-commands", handlers.GetMyCommandsWithTracking) // ✅ Avec suivi
|
cartGroupV1.GET("/my-commands", handlers.GetMyCommandsWithTracking) // ✅ Avec suivi
|
||||||
|
|
||||||
// ⭐ NOUVEAUX - SUIVI CLIENT TEMPS RÉEL
|
// ⭐ NOUVEAUX - SUIVI CLIENT TEMPS RÉEL
|
||||||
cartGroupV1.GET("/commands/:id/eta", handlers.GetOrderETA) // ✅ AJOUTÉ
|
cartGroupV1.GET("/commands/:id/eta", handlers.GetOrderETA) // ✅ AJOUTÉ
|
||||||
|
|||||||
@@ -174,11 +174,17 @@ export const loginUser = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
let errorMessage = "Erreur de connexion";
|
||||||
console.error("❌ [LOGIN] Erreur API:", errorData);
|
try {
|
||||||
|
const errorData = await response.json();
|
||||||
|
errorMessage = errorData.error || errorData.message || errorMessage;
|
||||||
|
} catch {
|
||||||
|
// body vide ou non-JSON
|
||||||
|
}
|
||||||
|
console.error("❌ [LOGIN] Erreur API:", response.status, errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: errorData.error || "Erreur de connexion",
|
message: errorMessage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,11 +265,17 @@ export const registerUser = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
let errorMessage = "Erreur d'inscription";
|
||||||
console.error("❌ [REGISTER] Erreur API:", errorData);
|
try {
|
||||||
|
const errorData = await response.json();
|
||||||
|
errorMessage = errorData.error || errorData.message || errorMessage;
|
||||||
|
} catch {
|
||||||
|
// body vide ou non-JSON
|
||||||
|
}
|
||||||
|
console.error("❌ [REGISTER] Erreur API:", response.status, errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: errorData.error || "Erreur d'inscription",
|
message: errorMessage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,13 @@ export default defineConfig({
|
|||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
build: {
|
build: {
|
||||||
chunkSizeWarningLimit: 1000, // Augmenter la limite à 1000 KB
|
chunkSizeWarningLimit: 1000, // Augmenter la limite à 1000 KB
|
||||||
}
|
},
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://localhost:8080',
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user