chore: build
This commit is contained in:
@@ -182,12 +182,12 @@ func (d *Database) GetProductsByCategory(category string) ([]models.Product, err
|
|||||||
return products, nil
|
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(`
|
err := d.GDB.Exec(`
|
||||||
UPDATE products
|
UPDATE products
|
||||||
SET name = ?, category = ?, description = ?, unit = ?, updated_at = ?
|
SET name = ?, category = ?, description = ?, unit = ?, coming_soon = ?, updated_at = ?
|
||||||
WHERE id = ?`,
|
WHERE id = ?`,
|
||||||
name, category, description, unit, time.Now(), productID).Error
|
name, category, description, unit, comingSoon, time.Now(), productID).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("erreur mise à jour produit: %w", err)
|
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 {
|
for _, price := range prices {
|
||||||
if err := d.GDB.Exec(`INSERT INTO product_prices (product_id, quantity, price, active_price) VALUES (?, ?, ?, ?)`,
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -635,7 +635,12 @@ func UpdateProduct(c *gin.Context) {
|
|||||||
|
|
||||||
log.Printf("🔄 [UpdateProduct] %s met à jour produit #%d", username, id)
|
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)
|
log.Printf("❌ [UpdateProduct] Erreur UPDATE: %v", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur mise à jour"})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur mise à jour"})
|
||||||
return
|
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
|
// ✅ RÉCUPÉRER LE PRODUIT MIS À JOUR
|
||||||
updatedProduct, _ := database.GetProductByID(id)
|
updatedProduct, _ := database.GetProductByID(id)
|
||||||
media, _ := database.GetMediaByProductID(id)
|
media, _ := database.GetMediaByProductID(id)
|
||||||
|
|||||||
Reference in New Issue
Block a user