chore: add new features for cabine

This commit is contained in:
2026-02-26 19:57:01 +01:00
parent 0fb4bd8a89
commit f91d4276cc
8 changed files with 467 additions and 323 deletions
+29 -2
View File
@@ -446,6 +446,35 @@ func (d *Database) CheckClientCanOrder(username string) (bool, float64, error) {
return true, 0, nil
}
func (d *Database) ResetClientPoint(username string, resetCancellationsPoint bool) error {
var query string
if resetCancellationsPoint {
query = `UPDATE clients SET point = 0, point_zipette = 0, updated_at = CURRENT_TIMESTAMP WHERE username = $1`
} else {
query = `UPDATE clients SET point = 0, updated_at = CURRENT_TIMESTAMP WHERE username = $1`
}
result, err := d.Exec(query, username)
if err != nil {
log.Printf("❌ [ResetClientPointAdmin] Erreur UPDATE: %v", err)
return fmt.Errorf("erreur reset points: %w", err)
}
rowsAffected, err := result.RowsAffected()
if err != nil {
return fmt.Errorf("erreur vérification: %w", err)
}
if rowsAffected == 0 {
return fmt.Errorf("client non trouvé")
}
// Invalider le cache Redis du client
cacheKey := fmt.Sprintf("client:%s", username)
Redis.Del(RedisCtx, cacheKey)
return nil
}
func (d *Database) ResetClientPenalties(username string, resetCancellationsCount bool) error {
log.Printf("🔄 [ResetClientPenalties] Reset pour %s (reset_count=%v)", username, resetCancellationsCount)
@@ -477,8 +506,6 @@ func (d *Database) ResetClientPenalties(username string, resetCancellationsCount
return fmt.Errorf("client non trouvé")
}
log.Printf("✅ [ResetClientPenalties] Reset effectué pour %s", username)
// Invalider le cache Redis du client
cacheKey := fmt.Sprintf("client:%s", username)
Redis.Del(RedisCtx, cacheKey)