chore: build
This commit is contained in:
@@ -115,6 +115,27 @@ func (d *Database) GetProductByID(id int) (models.Product, error) {
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProductNamesByIDs retourne un map id→name pour une liste d'IDs.
|
||||||
|
func (d *Database) GetProductNamesByIDs(ids []int) (map[int]string, error) {
|
||||||
|
result := make(map[int]string, len(ids))
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
rows, err := d.GDB.Raw(`SELECT id, name FROM products WHERE id IN ?`, ids).Rows()
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
for rows.Next() {
|
||||||
|
var id int
|
||||||
|
var name string
|
||||||
|
if err := rows.Scan(&id, &name); err == nil {
|
||||||
|
result[id] = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Database) GetAllProducts() ([]models.Product, error) {
|
func (d *Database) GetAllProducts() ([]models.Product, error) {
|
||||||
log.Println("📦 [GetAllProducts] START")
|
log.Println("📦 [GetAllProducts] START")
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ func GetMyPointsRewards(c *gin.Context) {
|
|||||||
|
|
||||||
reward := settings.PointsReward
|
reward := settings.PointsReward
|
||||||
|
|
||||||
|
type EligibleConfigResponse struct {
|
||||||
|
Category string `json:"category"`
|
||||||
|
AllProducts bool `json:"all_products"`
|
||||||
|
ProductIDs []int `json:"product_ids"`
|
||||||
|
ProductNames []string `json:"product_names"`
|
||||||
|
Amount float64 `json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
type PoolInfo struct {
|
type PoolInfo struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -47,9 +55,20 @@ func GetMyPointsRewards(c *gin.Context) {
|
|||||||
RewardsEarned int `json:"rewards_earned"`
|
RewardsEarned int `json:"rewards_earned"`
|
||||||
RewardsClaimed int `json:"rewards_claimed"`
|
RewardsClaimed int `json:"rewards_claimed"`
|
||||||
RewardsAvailable int `json:"rewards_available"`
|
RewardsAvailable int `json:"rewards_available"`
|
||||||
EligibleConfigs []models.RewardCategoryConfig `json:"eligible_configs"`
|
EligibleConfigs []EligibleConfigResponse `json:"eligible_configs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collecter tous les product_ids nécessaires en un seul passage
|
||||||
|
allProductIDs := make([]int, 0)
|
||||||
|
if reward != nil {
|
||||||
|
for _, cfg := range reward.CategoryConfigs {
|
||||||
|
if !cfg.AllProducts {
|
||||||
|
allProductIDs = append(allProductIDs, cfg.ProductIDs...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
productNames, _ := database.GetProductNamesByIDs(allProductIDs)
|
||||||
|
|
||||||
pools := make([]PoolInfo, 0, len(settings.PointsPools))
|
pools := make([]PoolInfo, 0, len(settings.PointsPools))
|
||||||
for _, pool := range settings.PointsPools {
|
for _, pool := range settings.PointsPools {
|
||||||
pts := pointsExtra[pool.Key]
|
pts := pointsExtra[pool.Key]
|
||||||
@@ -69,12 +88,25 @@ func GetMyPointsRewards(c *gin.Context) {
|
|||||||
for _, c := range pool.Categories {
|
for _, c := range pool.Categories {
|
||||||
poolCats[c] = true
|
poolCats[c] = true
|
||||||
}
|
}
|
||||||
eligibleConfigs := make([]models.RewardCategoryConfig, 0)
|
eligibleConfigs := make([]EligibleConfigResponse, 0)
|
||||||
if reward != nil {
|
if reward != nil {
|
||||||
for _, cfg := range reward.CategoryConfigs {
|
for _, cfg := range reward.CategoryConfigs {
|
||||||
if poolCats[cfg.Category] {
|
if !poolCats[cfg.Category] {
|
||||||
eligibleConfigs = append(eligibleConfigs, cfg)
|
continue
|
||||||
}
|
}
|
||||||
|
names := make([]string, 0, len(cfg.ProductIDs))
|
||||||
|
for _, pid := range cfg.ProductIDs {
|
||||||
|
if n, ok := productNames[pid]; ok {
|
||||||
|
names = append(names, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eligibleConfigs = append(eligibleConfigs, EligibleConfigResponse{
|
||||||
|
Category: cfg.Category,
|
||||||
|
AllProducts: cfg.AllProducts,
|
||||||
|
ProductIDs: cfg.ProductIDs,
|
||||||
|
ProductNames: names,
|
||||||
|
Amount: cfg.Amount,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2145,6 +2145,7 @@ export type RewardCategoryConfig = {
|
|||||||
category: string;
|
category: string;
|
||||||
all_products: boolean;
|
all_products: boolean;
|
||||||
product_ids: number[];
|
product_ids: number[];
|
||||||
|
product_names: string[];
|
||||||
amount: number;
|
amount: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -315,13 +315,21 @@ function ConsultationHistorique() {
|
|||||||
<span className="reward-pool-name">{pool.name}</span>
|
<span className="reward-pool-name">{pool.name}</span>
|
||||||
<span className="reward-pool-pts">{pool.points} pts</span>
|
<span className="reward-pool-pts">{pool.points} pts</span>
|
||||||
</div>
|
</div>
|
||||||
{pool.eligible_configs.some((cfg) => cfg.all_products) && (
|
{pool.eligible_configs.length > 0 && (
|
||||||
<div className="reward-eligible-cats">
|
<div className="reward-eligible-cats">
|
||||||
{pool.eligible_configs.filter((cfg) => cfg.all_products).map((cfg) => (
|
{pool.eligible_configs.map((cfg) =>
|
||||||
|
cfg.all_products ? (
|
||||||
<span key={cfg.category} className="reward-eligible-cat">
|
<span key={cfg.category} className="reward-eligible-cat">
|
||||||
{cfg.category}{cfg.amount > 0 ? ` — ${cfg.amount}€` : ""}
|
{cfg.category}{cfg.amount > 0 ? ` — ${cfg.amount}€` : ""}
|
||||||
</span>
|
</span>
|
||||||
))}
|
) : (
|
||||||
|
cfg.product_names.map((name) => (
|
||||||
|
<span key={name} className="reward-eligible-cat">
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
))
|
||||||
|
)
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="reward-progress-bar">
|
<div className="reward-progress-bar">
|
||||||
|
|||||||
Reference in New Issue
Block a user