chore: build

This commit is contained in:
2026-06-15 19:13:51 +02:00
parent c7d43e7641
commit 48e6cbcb4c
4 changed files with 656 additions and 142 deletions
+16 -3
View File
@@ -2,6 +2,7 @@ package handlers
import (
"gestion/db"
"gestion/models"
"gestion/utils"
"log"
"net/http"
@@ -166,7 +167,8 @@ func ClaimMyReward(c *gin.Context) {
}
var req struct {
PoolKey string `json:"pool_key" binding:"required"`
PoolKey string `json:"pool_key" binding:"required"`
ProductID int `json:"product_id"` // optionnel : 0 = automatique (1 seul item)
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "pool_key requis"})
@@ -215,11 +217,22 @@ func ClaimMyReward(c *gin.Context) {
return
}
// Si le client a sélectionné un produit spécifique parmi plusieurs, ne donner que celui-là
itemsToAdd := reward.RewardItems
if req.ProductID > 0 && len(reward.RewardItems) > 1 {
for _, item := range reward.RewardItems {
if item.ProductID == req.ProductID {
itemsToAdd = []models.RewardItem{item}
break
}
}
}
// Ajouter les produits récompense au panier si configurés
productAdded := false
var productNames []string
if len(reward.RewardItems) > 0 {
if added, addErr := database.AddRewardsToBasket(username, reward.RewardItems, req.PoolKey); addErr == nil && len(added) > 0 {
if len(itemsToAdd) > 0 {
if added, addErr := database.AddRewardsToBasket(username, itemsToAdd, req.PoolKey); addErr == nil && len(added) > 0 {
productAdded = true
for _, item := range added {
productNames = append(productNames, item.ProductName)