From b5196c5f22ed736e79ec477132fb23ce242c2c66 Mon Sep 17 00:00:00 2001 From: Xor290 Date: Thu, 11 Jun 2026 19:04:04 +0200 Subject: [PATCH] chore: build --- backend/gestion/db/db_product.go | 8 ++++---- backend/gestion/handlers/product.go | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/backend/gestion/db/db_product.go b/backend/gestion/db/db_product.go index dc640f2d..0c7c8d83 100644 --- a/backend/gestion/db/db_product.go +++ b/backend/gestion/db/db_product.go @@ -182,12 +182,12 @@ func (d *Database) GetProductsByCategory(category string) ([]models.Product, err return products, nil } -func (d *Database) UpdateProduct(productID int, name, category, description, unit string, prices []models.ProductPrice) error { +func (d *Database) UpdateProduct(productID int, name, category, description, unit string, comingSoon bool, prices []models.ProductPrice) error { err := d.GDB.Exec(` UPDATE products - SET name = ?, category = ?, description = ?, unit = ?, updated_at = ? + SET name = ?, category = ?, description = ?, unit = ?, coming_soon = ?, updated_at = ? WHERE id = ?`, - name, category, description, unit, time.Now(), productID).Error + name, category, description, unit, comingSoon, time.Now(), productID).Error if err != nil { return fmt.Errorf("erreur mise à jour produit: %w", err) } @@ -197,7 +197,7 @@ func (d *Database) UpdateProduct(productID int, name, category, description, uni for _, price := range prices { if err := d.GDB.Exec(`INSERT INTO product_prices (product_id, quantity, price, active_price) VALUES (?, ?, ?, ?)`, productID, price.Quantity, price.Price, price.ActivePrice).Error; err != nil { - log.Printf("❌ [UpdateProduct] Erreur prix: %v", err) + return fmt.Errorf("erreur insertion prix: %w", err) } } diff --git a/backend/gestion/handlers/product.go b/backend/gestion/handlers/product.go index cd83cb40..ab291227 100644 --- a/backend/gestion/handlers/product.go +++ b/backend/gestion/handlers/product.go @@ -635,7 +635,12 @@ func UpdateProduct(c *gin.Context) { log.Printf("🔄 [UpdateProduct] %s met à jour produit #%d", username, id) - if err := database.UpdateProduct(id, updateData.Name, updateData.Category, updateData.Description, updateData.Unit, updateData.Prices); err != nil { + comingSoon := false + if updateData.ComingSoon != nil { + comingSoon = *updateData.ComingSoon + } + + if err := database.UpdateProduct(id, updateData.Name, updateData.Category, updateData.Description, updateData.Unit, comingSoon, updateData.Prices); err != nil { log.Printf("❌ [UpdateProduct] Erreur UPDATE: %v", err) c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur mise à jour"}) return @@ -647,12 +652,6 @@ func UpdateProduct(c *gin.Context) { } } - if updateData.ComingSoon != nil { - if err := database.SetProductComingSoon(id, *updateData.ComingSoon); err != nil { - log.Printf("⚠️ [UpdateProduct] Erreur mise à jour coming_soon: %v", err) - } - } - // ✅ RÉCUPÉRER LE PRODUIT MIS À JOUR updatedProduct, _ := database.GetProductByID(id) media, _ := database.GetMediaByProductID(id)