feat: desactive and active price for product
This commit is contained in:
@@ -43,3 +43,31 @@ func (d *Database) DeleteProductPrice(priceID int) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Database) AddActivePrice(priceID int) error {
|
||||||
|
result := d.GDB.Model(&models.ProductPrice{}).
|
||||||
|
Where("id = ?", priceID).
|
||||||
|
Update("active_price", true)
|
||||||
|
|
||||||
|
if result.Error != nil {
|
||||||
|
return fmt.Errorf("erreur lors de l'activation du prix: %w", result.Error)
|
||||||
|
}
|
||||||
|
if result.RowsAffected == 0 {
|
||||||
|
return fmt.Errorf("prix introuvable")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Database) DeActivePrice(priceID int) error {
|
||||||
|
result := d.GDB.Model(&models.ProductPrice{}).
|
||||||
|
Where("id = ?", priceID).
|
||||||
|
Update("active_price", false)
|
||||||
|
|
||||||
|
if result.Error != nil {
|
||||||
|
return fmt.Errorf("erreur lors de l'activation du prix: %w", result.Error)
|
||||||
|
}
|
||||||
|
if result.RowsAffected == 0 {
|
||||||
|
return fmt.Errorf("prix introuvable")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -849,6 +849,50 @@ func UploadMedia(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ActivePrice(c *gin.Context) {
|
||||||
|
database := c.MustGet("database").(*db.Database)
|
||||||
|
role := c.GetString("role")
|
||||||
|
if role != "admin" {
|
||||||
|
c.JSON(http.StatusForbidden, gin.H{"error": "Accès refusé"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil || id <= 0 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "ID invalide"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.AddActivePrice(id); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"message": "Prix activé avec succès"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func DesActivePrice(c *gin.Context) {
|
||||||
|
database := c.MustGet("database").(*db.Database)
|
||||||
|
role := c.GetString("role")
|
||||||
|
if role != "admin" {
|
||||||
|
c.JSON(http.StatusForbidden, gin.H{"error": "Accès refusé"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil || id <= 0 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "ID invalide"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := database.DeActivePrice(id); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, gin.H{"message": "Prix désactivé avec succès"})
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// DELETE PRODUCT - VERSION SÉCURISÉE
|
// DELETE PRODUCT - VERSION SÉCURISÉE
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|||||||
@@ -18,11 +18,12 @@ type Product struct {
|
|||||||
func (Product) TableName() string { return "products" }
|
func (Product) TableName() string { return "products" }
|
||||||
|
|
||||||
type ProductPrice struct {
|
type ProductPrice struct {
|
||||||
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
|
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
ProductID int `json:"product_id" gorm:"column:product_id;index"`
|
ProductID int `json:"product_id" gorm:"column:product_id;index"`
|
||||||
Quantity float64 `json:"quantity" gorm:"column:quantity" binding:"required"`
|
Quantity float64 `json:"quantity" gorm:"column:quantity" binding:"required"`
|
||||||
Price float64 `json:"price" gorm:"column:price" binding:"required"`
|
Price float64 `json:"price" gorm:"column:price" binding:"required"`
|
||||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||||
|
ActivePrice bool `json:"active_price" gorm:"column:active_price;default:true" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ProductPrice) TableName() string { return "product_prices" }
|
func (ProductPrice) TableName() string { return "product_prices" }
|
||||||
|
|||||||
@@ -199,6 +199,9 @@ func SetupRoutes(router *gin.Engine, database *db.Database, geoService *services
|
|||||||
// ============================================
|
// ============================================
|
||||||
adminGroupV2.GET("/stats", handlers.GetAdminStats)
|
adminGroupV2.GET("/stats", handlers.GetAdminStats)
|
||||||
|
|
||||||
|
adminGroupV2.POST("/active/product/price/:id", handlers.ActivePrice)
|
||||||
|
adminGroupV2.POST("/desactive/product/price/:id", handlers.DesActivePrice)
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// COMMANDES - GESTION DE BASE
|
// COMMANDES - GESTION DE BASE
|
||||||
// ============================================
|
// ============================================
|
||||||
@@ -348,8 +351,8 @@ func SetupRoutes(router *gin.Engine, database *db.Database, geoService *services
|
|||||||
livreurGroupV1.GET("/deliveries", handlers.GetMyDeliveries) // ✅ Données filtrées
|
livreurGroupV1.GET("/deliveries", handlers.GetMyDeliveries) // ✅ Données filtrées
|
||||||
livreurGroupV1.GET("/deliveries/:id", handlers.GetDeliveryDetails) // ✅ Détail filtré
|
livreurGroupV1.GET("/deliveries/:id", handlers.GetDeliveryDetails) // ✅ Détail filtré
|
||||||
livreurGroupV1.POST("/deliveries/:id/start", handlers.StartDelivery)
|
livreurGroupV1.POST("/deliveries/:id/start", handlers.StartDelivery)
|
||||||
livreurGroupV1.PUT("/deliveries/:id/status", handlers.UpdateDeliveryStatus) // ✅ Avec GPS
|
livreurGroupV1.PUT("/deliveries/:id/status", handlers.UpdateDeliveryStatus) // ✅ Avec GPS
|
||||||
livreurGroupV1.POST("/deliveries/:id/issue", handlers.ReportDeliveryIssue) // Motif non-livraison
|
livreurGroupV1.POST("/deliveries/:id/issue", handlers.ReportDeliveryIssue) // Motif non-livraison
|
||||||
livreurGroupV1.GET("/deliveries/:id/nav-link", handlers.GetLivreurNavLink) // Lien Waze App
|
livreurGroupV1.GET("/deliveries/:id/nav-link", handlers.GetLivreurNavLink) // Lien Waze App
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|||||||
Reference in New Issue
Block a user