361 lines
18 KiB
Go
361 lines
18 KiB
Go
// ============================================
|
|
// routes/routes.go - VERSION CORRIGÉE COMPLÈTE
|
|
// ============================================
|
|
|
|
package routes
|
|
|
|
import (
|
|
"gestion/db"
|
|
"gestion/handlers"
|
|
"gestion/middleware"
|
|
"gestion/services"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SetupRoutes(router *gin.Engine, database *db.Database, geoService *services.GeoService) {
|
|
|
|
// ============================================
|
|
// 🔐 MIDDLEWARE GLOBAL
|
|
// ============================================
|
|
router.Use(func(c *gin.Context) {
|
|
c.Set("database", database)
|
|
c.Set("geoService", geoService)
|
|
})
|
|
|
|
// ============================================
|
|
// 📋 PATTERN v1: CLIENT API
|
|
// ============================================
|
|
|
|
// ============================================
|
|
// 👤 AUTH ROUTES (v1) - PUBLIC
|
|
// ============================================
|
|
authGroupV1 := router.Group("/api/v1/auth")
|
|
{
|
|
authGroupV1.POST("/login", handlers.LoginClient)
|
|
authGroupV1.POST("/logout", handlers.LogoutClient)
|
|
}
|
|
|
|
// Route change-password (auth client requise)
|
|
authProtectedV1 := router.Group("/api/v1/auth")
|
|
authProtectedV1.Use(middleware.ClientMiddleware)
|
|
{
|
|
authProtectedV1.PUT("/change-password", handlers.ChangePassword)
|
|
}
|
|
|
|
// ============================================
|
|
// 📦 PRODUITS & CATÉGORIES (v1) - PUBLIC (SANS middleware!)
|
|
// ============================================
|
|
productsGroupV1 := router.Group("/api/v1")
|
|
{
|
|
productsGroupV1.GET("/products", handlers.GetAllProducts)
|
|
productsGroupV1.GET("/products/:id", handlers.GetProductByID)
|
|
productsGroupV1.GET("/products/category/:category", handlers.GetProductsByCategory)
|
|
productsGroupV1.GET("/categories", handlers.GetCategories)
|
|
productsGroupV1.GET("/app-settings", handlers.GetPublicSettings)
|
|
}
|
|
|
|
// ============================================
|
|
// 🛒 PANIER (v1) - AVEC CLIENT MIDDLEWARE + SESSION
|
|
// ============================================
|
|
cartGroupV1 := router.Group("/api/v1")
|
|
cartGroupV1.Use(middleware.ClientMiddleware)
|
|
cartGroupV1.Use(middleware.ClientSessionMiddleware)
|
|
{
|
|
// Panier
|
|
cartGroupV1.POST("/panier/add", handlers.AddProductsBasket)
|
|
cartGroupV1.GET("/panier/:username", handlers.GetAllBaskets)
|
|
cartGroupV1.DELETE("/panier/remove", handlers.DeleteProductFromBasket)
|
|
cartGroupV1.DELETE("/panier/clear", handlers.ClearBasket) // ✅ CORRIGÉ - Sans :username
|
|
|
|
// Commandes
|
|
cartGroupV1.POST("/checkout", middleware.OrderHoursMiddleware, middleware.BlockClientIfPenalty, 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É
|
|
cartGroupV1.GET("/commands/:id/status", handlers.GetCommandStatus) // ✅ AJOUTÉ
|
|
cartGroupV1.GET("/commands/:id/tracking", handlers.GetCommandTracking) // ✅ AJOUTÉ
|
|
cartGroupV1.GET("/commands/:id", handlers.GetCommandByID)
|
|
cartGroupV1.GET("/commands/:id/items", handlers.GetCommandItemsWithDetails)
|
|
// Approbation livraison
|
|
cartGroupV1.POST("/commands/:id/approve", handlers.ApproveDelivery)
|
|
cartGroupV1.POST("/commands/:id/address/respond", handlers.RespondToAddressProposal)
|
|
// ⭐ NOUVEAU - HISTORIQUE DES COMMANDES TERMINÉES
|
|
cartGroupV1.GET("/my-commands/history/detailed", handlers.GetMyCompletedOrdersWithItems)
|
|
cartGroupV1.GET("/commands/:id/history", handlers.GetOrderHistory)
|
|
// ⭐ NOUVEAU - ANNULATION DE COMMANDE (CLIENT)
|
|
cartGroupV1.POST("/commands/:id/cancel", handlers.CancelCommandByClient)
|
|
cartGroupV1.GET("/my-cancellation-history", handlers.GetMyCancellationHistory)
|
|
|
|
// ⭐ NOUVEAU - HISTORIQUE DES COMMANDES TERMINÉES
|
|
cartGroupV1.GET("/my-commands/history", handlers.GetClientCommandsHistory)
|
|
// ⭐⭐ PÉNALITÉS CLIENT
|
|
cartGroupV1.GET("/penalties", handlers.GetMyPenalties) // Voir mes pénalités
|
|
|
|
// 🔔 NOTIFICATIONS CLIENT
|
|
cartGroupV1.GET("/notifications", handlers.GetClientNotifications)
|
|
cartGroupV1.POST("/notifications/read", handlers.MarkNotificationsRead)
|
|
|
|
// 📱 PUSH TOKEN
|
|
cartGroupV1.POST("/push-token", handlers.RegisterPushToken)
|
|
cartGroupV1.DELETE("/push-token", handlers.UnregisterPushToken)
|
|
|
|
// 👤 PROFIL CLIENT
|
|
cartGroupV1.GET("/profile", handlers.GetMyProfile) // ✅ Récupérer mon profil
|
|
cartGroupV1.PUT("/profile/update", handlers.UpdateMyProfile) // ✅ Modifier mon profil
|
|
|
|
// 🎁 PARRAINAGE CLIENT
|
|
cartGroupV1.GET("/referral/balance", handlers.GetMyReferralBalance)
|
|
}
|
|
|
|
// ============================================
|
|
// 🌍 GÉOCODAGE PUBLIC (v1)
|
|
// ============================================
|
|
geoGroupV1 := router.Group("/api/v1")
|
|
{
|
|
geoGroupV1.POST("/geocode", handlers.GeocodeAddress)
|
|
geoGroupV1.POST("/validate-address", handlers.ValidateAddress)
|
|
}
|
|
|
|
// ============================================
|
|
// 📋 PATTERN v2: ADMIN API
|
|
// ============================================
|
|
|
|
// ============================================
|
|
// 👤 ADMIN AUTH (v2) - PUBLIC
|
|
// ============================================
|
|
adminAuthGroupV2 := router.Group("/api/v2/admin/auth")
|
|
{
|
|
adminAuthGroupV2.POST("/register", handlers.RegisterAdmin)
|
|
adminAuthGroupV2.POST("/login", handlers.LoginAdmin)
|
|
adminAuthGroupV2.POST("/logout", handlers.LogoutAdmin)
|
|
}
|
|
|
|
// ============================================
|
|
// 🔒 ADMIN PROTECTED (v2) - AVEC ADMIN MIDDLEWARE
|
|
// ============================================
|
|
adminGroupV2 := router.Group("/api/v2/admin/protected")
|
|
adminGroupV2.Use(middleware.AdminMiddleware)
|
|
{
|
|
// PUSH TOKEN ADMIN
|
|
adminGroupV2.POST("/push-token", handlers.RegisterAdminPushToken)
|
|
adminGroupV2.DELETE("/push-token", handlers.UnregisterAdminPushToken)
|
|
|
|
// 🔔 NOTIFICATIONS ADMIN
|
|
adminGroupV2.GET("/notifications", handlers.GetLivreurNotifications)
|
|
adminGroupV2.POST("/notifications/read", handlers.MarkLivreurNotificationsRead)
|
|
|
|
// ============================================
|
|
// CLIENT - GESTION
|
|
// ============================================
|
|
adminGroupV2.GET("/all/clients", handlers.GetAllClients)
|
|
adminGroupV2.GET("/all/users", handlers.GetAllUsers)
|
|
// ⭐⭐ MODIFICATION DE PROFILS PAR ADMIN
|
|
adminGroupV2.PUT("/clients/:id", handlers.UpdateClientByAdmin) // ✅ Modifier un client
|
|
adminGroupV2.PUT("/users/:id", handlers.UpdateUserByAdmin) // ✅ Modifier un user
|
|
adminGroupV2.POST("/clients", handlers.AdminCreateClient)
|
|
adminGroupV2.DELETE("/clients/:id", handlers.DeleteClient)
|
|
adminGroupV2.DELETE("/users/:id", handlers.DeleteUser)
|
|
adminGroupV2.POST("/users", handlers.CreateUser)
|
|
// Get location livreur
|
|
adminGroupV2.GET("/commands/:id/deliveryman/location", handlers.GetDeliverymanLocationForCommand)
|
|
// ============================================
|
|
// ADDRESSES - GESTION
|
|
// ============================================
|
|
adminGroupV2.POST("/add/address", handlers.AddAddress)
|
|
adminGroupV2.DELETE("/delete/address", handlers.DeleteAddress)
|
|
adminGroupV2.GET("/addresses", handlers.GetAllAddress)
|
|
// ============================================
|
|
// PRODUITS - GESTION
|
|
// ============================================
|
|
adminGroupV2.POST("/products", handlers.CreateProduct)
|
|
adminGroupV2.GET("/products", handlers.GetAllProducts)
|
|
adminGroupV2.GET("/products/:id", handlers.GetProductByID)
|
|
adminGroupV2.PUT("/products/:id", handlers.UpdateProduct)
|
|
adminGroupV2.DELETE("/products/:id", handlers.DeleteProduct)
|
|
adminGroupV2.POST("/products/:id/media", handlers.UploadMedia)
|
|
adminGroupV2.DELETE("/products/:id/media/:media_id", handlers.DeleteMedia)
|
|
// ============================================
|
|
// CATÉGORIES - GESTION ADMIN
|
|
// ============================================
|
|
adminGroupV2.POST("/categories", handlers.CreateCategory)
|
|
adminGroupV2.PUT("/categories/:id", handlers.UpdateCategory)
|
|
adminGroupV2.DELETE("/categories/:id", handlers.DeleteCategory)
|
|
// ============================================
|
|
// COMMANDES - GESTION DE BASE
|
|
// ============================================
|
|
adminGroupV2.GET("/orders", handlers.GetAllCommands)
|
|
adminGroupV2.GET("/orders/:id", handlers.GetCommandByID)
|
|
adminGroupV2.PUT("/orders/:id/address", handlers.UpdateCommandAddress)
|
|
adminGroupV2.POST("/orders/:id/propose-address", handlers.ProposeAddressChange)
|
|
adminGroupV2.PUT("/orders/:id/status", handlers.UpdateCommandStatusAdmin)
|
|
adminGroupV2.POST("/orders/:id/force-validate", handlers.ValidateDelivery)
|
|
adminGroupV2.POST("/orders/:id/confirm-reception", handlers.StaffApproveDelivery)
|
|
adminGroupV2.POST("/orders/:id/notify-client", handlers.NotifyClientToDescend)
|
|
adminGroupV2.GET("/orders/:id/items", handlers.ShowItems)
|
|
adminGroupV2.DELETE("/orders/:id/items/:item_id", handlers.DeleteCommandItem)
|
|
adminGroupV2.DELETE("/orders/:id", handlers.DeleteCommandByCabine)
|
|
|
|
// ============================================
|
|
// ⭐ AUTO-ASSIGNATION GPS - ROUTES CRITIQUES
|
|
// ============================================
|
|
adminGroupV2.POST("/orders/:id/auto-assign", handlers.AutoAssignNearestDeliveryPerson)
|
|
adminGroupV2.POST("/orders/auto-assign-all", handlers.AutoAssignAllPendingCommands)
|
|
|
|
// ============================================
|
|
// RECHERCHE DU LIVREUR LE PLUS PROCHE
|
|
// ============================================
|
|
adminGroupV2.POST("/delivery/nearest", handlers.FindNearestDeliveryPerson)
|
|
adminGroupV2.POST("/delivery/distances", handlers.GetAllDeliveryDistances)
|
|
|
|
// ============================================
|
|
// GESTION DES QUEUES DES LIVREURS
|
|
// ============================================
|
|
adminGroupV2.GET("/delivery/queues", handlers.GetAllDeliveryQueues)
|
|
adminGroupV2.GET("/delivery/:username/queue", handlers.GetDeliverymanQueue)
|
|
|
|
// ============================================
|
|
// GÉOCODAGE (Admin uniquement)
|
|
// ============================================
|
|
adminGroupV2.POST("/validate-address", handlers.ValidateAddress)
|
|
adminGroupV2.POST("/geocode", handlers.GeocodeAddress)
|
|
|
|
// ============================================
|
|
// GESTION LIVREURS
|
|
// ============================================
|
|
adminGroupV2.GET("/delivery-persons", handlers.GetAvailableDeliveryPersons)
|
|
adminGroupV2.GET("/delivery-persons/:username", handlers.GetDeliveryPersonDetails)
|
|
adminGroupV2.POST("/delivery-persons/:username/assign/:command_id", handlers.AssignDeliveryPerson)
|
|
adminGroupV2.PUT("/delivery-persons/:username/status", handlers.UpdateDeliveryPersonStatusAdmin)
|
|
adminGroupV2.GET("/delivery-persons/:username/stats", handlers.GetDeliveryPersonStats)
|
|
adminGroupV2.GET("/delivery-persons/:username/history", handlers.GetDeliveryPersonHistory)
|
|
adminGroupV2.GET("/delivery-persons/:username/location", handlers.GetDeliveryPersonLocation) // ⭐ AJOUTÉ
|
|
adminGroupV2.PUT("/delivery-persons/update/:username/location", handlers.UpdateDeliveryPersonLocationAdmin)
|
|
adminGroupV2.DELETE("/delivery-persons/:username/queue/:command_id", handlers.RemoveCommandFromQueue)
|
|
adminGroupV2.GET("/delivery-persons/:username/map-links", handlers.GetDeliveryPersonMapLinks)
|
|
// Commandes annulées
|
|
adminGroupV2.GET("/orders/cancelled", handlers.GetAllCancelledOrders)
|
|
// ============================================
|
|
// ⭐⭐ PÉNALITÉS - GESTION ADMIN
|
|
// ============================================
|
|
adminGroupV2.POST("/penalty", handlers.ApplyClientPenalty) // Appliquer pénalité
|
|
adminGroupV2.GET("/client/:username/penalties", handlers.GetClientPenaltiesAdmin) // Voir pénalités client
|
|
adminGroupV2.POST("/client/:username/penalties/reset", handlers.ResetClientPenaltiesAdmin) // Reset pénalités
|
|
adminGroupV2.GET("/penalties/all", handlers.GetAllClientsWithPenalties) // Liste clients avec pénalités
|
|
adminGroupV2.GET("/penalties/stats", handlers.GetPenaltiesStats)
|
|
|
|
// ============================================
|
|
// ⚙️ PARAMÈTRES GLOBAUX
|
|
// ============================================
|
|
adminGroupV2.GET("/settings", handlers.GetSettings)
|
|
adminGroupV2.PUT("/settings", handlers.UpdateSettings)
|
|
|
|
// 🎁 PARRAINAGE ADMIN
|
|
adminGroupV2.GET("/client/:username/referral", handlers.GetClientReferralAdmin)
|
|
adminGroupV2.POST("/client/:username/referral/credit", handlers.CreditClientReferralAdmin)
|
|
|
|
// ============================================
|
|
// ⭐⭐ ALERTES POLICE - GESTION ADMIN
|
|
// ============================================
|
|
adminGroupV2.GET("/alerts/:id", handlers.GetAlert) // Détails d'une alerte
|
|
adminGroupV2.DELETE("/delete/alerts/:id", handlers.DeleteAlert) // Supprimer une alerte
|
|
adminGroupV2.GET("/alerts", handlers.GetActiveAlerts) // ⭐ AJOUTÉ - Toutes les alertes actives
|
|
adminGroupV2.GET("/all/alerts", handlers.GetAllAlerts)
|
|
|
|
}
|
|
|
|
// ============================================
|
|
// 👨💼 CABINE ROUTES (v1) - AVEC CABINE MIDDLEWARE
|
|
// ============================================
|
|
cabineGroupV1 := router.Group("/api/v1/cabine")
|
|
cabineGroupV1.Use(middleware.CabineMiddleware)
|
|
{
|
|
// ============================================
|
|
// ADDRESSES - GESTION
|
|
// ============================================
|
|
cabineGroupV1.POST("/add/address", handlers.AddAddress)
|
|
cabineGroupV1.DELETE("/delete/address", handlers.DeleteAddress)
|
|
cabineGroupV1.GET("/addresses", handlers.GetAllAddress)
|
|
// PUSH TOKEN CABINE
|
|
cabineGroupV1.POST("/push-token", handlers.RegisterCabinePushToken)
|
|
cabineGroupV1.DELETE("/push-token", handlers.UnregisterCabinePushToken)
|
|
|
|
// 🔔 NOTIFICATIONS CABINE
|
|
cabineGroupV1.GET("/notifications", handlers.GetLivreurNotifications)
|
|
cabineGroupV1.POST("/notifications/read", handlers.MarkLivreurNotificationsRead)
|
|
|
|
cabineGroupV1.GET("/commands/:id/items", handlers.ShowItems)
|
|
cabineGroupV1.POST("/commands/:id/confirm-reception", handlers.StaffApproveDelivery)
|
|
cabineGroupV1.POST("/commands/:id/assign", handlers.AssignDeliveryPerson)
|
|
cabineGroupV1.POST("/commands/:id/notify-client", handlers.NotifyClientToDescend)
|
|
cabineGroupV1.PUT("/items/:item_id/status", handlers.UpdateItemStatus)
|
|
cabineGroupV1.GET("/commands/:id/deliveryman/location", handlers.GetDeliverymanLocationForCommand)
|
|
cabineGroupV1.GET("/all/deliveryman", handlers.GetAllDeliveryMen)
|
|
cabineGroupV1.DELETE("/commands/:id", handlers.DeleteCommandByCabine)
|
|
cabineGroupV1.POST("/commands/:id/propose-address", handlers.ProposeAddressChange)
|
|
// ⭐ NOUVEAU - ANNULATION PAR CABINE
|
|
cabineGroupV1.GET("/commands/cancelled", handlers.GetAllCancelledOrders)
|
|
cabineGroupV1.GET("/client/:username/penalties", handlers.GetClientPenaltiesAdmin) // Voir pénalités client
|
|
cabineGroupV1.POST("/client/:username/penalties/reset", handlers.ResetClientPenaltiesAdmin) // Reset pénalités
|
|
cabineGroupV1.POST("/client/:username/point/reset", handlers.ResetClientPointAdmin)
|
|
cabineGroupV1.GET("/penalties/all", handlers.GetAllClientsWithPenalties) // Liste clients avec pénalités
|
|
cabineGroupV1.GET("/penalties/stats", handlers.GetPenaltiesStats)
|
|
|
|
// ============================================
|
|
// ⭐⭐ ALERTES POLICE - CONSULTATION CABINE
|
|
// ============================================
|
|
cabineGroupV1.GET("/alerts/:id", handlers.GetAlert) // Détails d'une alerte
|
|
cabineGroupV1.GET("/alerts", handlers.GetActiveAlerts) // ⭐ AJOUTÉ - Toutes les alertes actives
|
|
cabineGroupV1.GET("/all/alerts", handlers.GetAllAlerts)
|
|
}
|
|
|
|
// ============================================
|
|
// 👨🚚 LIVREUR ROUTES (v1) - AVEC LIVREUR MIDDLEWARE
|
|
// ============================================
|
|
livreurGroupV1 := router.Group("/api/v1/livreur")
|
|
livreurGroupV1.Use(middleware.LivreurMiddleware)
|
|
{
|
|
// ============================================
|
|
// LIVRAISONS
|
|
// ============================================
|
|
livreurGroupV1.GET("/deliveries", handlers.GetMyDeliveries) // ✅ Données filtrées
|
|
livreurGroupV1.GET("/deliveries/:id", handlers.GetDeliveryDetails) // ✅ Détail filtré
|
|
livreurGroupV1.POST("/deliveries/:id/start", handlers.StartDelivery)
|
|
livreurGroupV1.PUT("/deliveries/:id/status", handlers.UpdateDeliveryStatus) // ✅ Avec GPS
|
|
|
|
// ============================================
|
|
// POSITION GPS
|
|
// ============================================
|
|
livreurGroupV1.POST("/location/update", handlers.UpdateLivreurLocation)
|
|
livreurGroupV1.GET("/location", handlers.GetMyLocation)
|
|
|
|
// ============================================
|
|
// STATUT LIVREUR
|
|
// ============================================
|
|
livreurGroupV1.POST("/update/status", handlers.UpdateDeliveryPersonStatus)
|
|
livreurGroupV1.GET("/status", handlers.GetMyStatus)
|
|
|
|
// ============================================
|
|
// QUEUE PERSONNELLE
|
|
// ============================================
|
|
livreurGroupV1.GET("/queue", handlers.GetMyQueue)
|
|
|
|
// ============================================
|
|
// ALERTES POLICE
|
|
// ============================================
|
|
livreurGroupV1.POST("/alert", handlers.AlertPolice) // ⭐ AJOUTÉ - Créer une alerte
|
|
livreurGroupV1.DELETE("/alert/:id", handlers.EndAlert) // Mettre fin à une alerte
|
|
livreurGroupV1.GET("/alerts", handlers.GetMyAlerts) // Voir mes alertes
|
|
livreurGroupV1.GET("/alert/:id", handlers.GetAlert) // Détail d'une alerte
|
|
|
|
// ============================================
|
|
// NOTIFICATIONS LIVREUR
|
|
// ============================================
|
|
livreurGroupV1.GET("/notifications", handlers.GetLivreurNotifications)
|
|
livreurGroupV1.POST("/notifications/read", handlers.MarkLivreurNotificationsRead)
|
|
livreurGroupV1.POST("/push-token", handlers.RegisterLivreurPushToken)
|
|
livreurGroupV1.DELETE("/push-token", handlers.UnregisterLivreurPushToken)
|
|
}
|
|
}
|