chore: refacto

This commit is contained in:
2026-04-20 19:41:52 +02:00
parent 5fc52c72ee
commit 2e9827af98
46 changed files with 497 additions and 648 deletions
+8 -1
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"gestion/models"
"strconv"
"gorm.io/gorm"
)
@@ -40,6 +41,7 @@ func DefaultSettings() models.AppSettings {
},
PointsEnabled: true,
ReferralEnabled: true,
ReferralAmount: 0,
PointsPools: []models.PointsPool{
{
Key: "pool_0",
@@ -90,7 +92,7 @@ func (d *Database) GetSettings() (models.AppSettings, error) {
Key string `gorm:"column:key"`
Value string `gorm:"column:value"`
}
if err := d.GDB.Raw(`SELECT key, value FROM app_settings`).Scan(&rows).Error; err != nil {
if err := d.GDB.Table("app_settings").Select("key, value").Scan(&rows).Error; err != nil {
return settings, fmt.Errorf("erreur lecture settings: %w", err)
}
@@ -109,6 +111,10 @@ func (d *Database) GetSettings() (models.AppSettings, error) {
}
case "referral_enabled":
settings.ReferralEnabled = row.Value == "true"
case "referral_amount":
if v, err := strconv.ParseFloat(row.Value, 64); err == nil {
settings.ReferralAmount = v
}
case "crypto_payment_enabled":
settings.CryptoPaymentEnabled = row.Value == "true"
case "crypto_only":
@@ -207,6 +213,7 @@ func (d *Database) UpdateSettings(s models.AppSettings) error {
{"points_enabled", boolStr(s.PointsEnabled)},
{"points_pools", string(poolsJSON)},
{"referral_enabled", boolStr(s.ReferralEnabled)},
{"referral_amount", strconv.FormatFloat(s.ReferralAmount, 'f', 2, 64)},
{"crypto_payment_enabled", boolStr(s.CryptoPaymentEnabled)},
{"crypto_only", boolStr(s.CryptoOnly)},
{"nowpayments_api_key", s.NowPaymentsAPIKey},