chore: build
Backend - Build & Lint / build (push) Successful in 31m59s
Frontend Admin - EAS Build / build (push) Successful in 1h32m56s

This commit is contained in:
Xor290
2026-11-01 13:08:58 +01:00
parent f3eaea4347
commit 0a18460f13
20 changed files with 1694 additions and 190 deletions
+17 -5
View File
@@ -76,8 +76,9 @@ func (d *Database) GetClientByID(id int) (*models.Client, error) {
return client, nil
}
// GetAllClients récupère tous les clients
func (d *Database) GetAllClients() ([]*models.Client, error) {
// GetAllClients récupère une page de clients, triée par date de création
// descendante, ainsi que le nombre total de clients en base.
func (d *Database) GetAllClients(limit, offset int) ([]*models.Client, int64, error) {
var rows []struct {
ID int `gorm:"column:id"`
Username string `gorm:"column:username"`
@@ -89,16 +90,25 @@ func (d *Database) GetAllClients() ([]*models.Client, error) {
Amende float64 `gorm:"column:amende"`
ReferralBalance float64 `gorm:"column:referral_balance"`
CancellationsCount int `gorm:"column:cancellations_count"`
LastPenaltyReason string `gorm:"column:last_penalty_reason"`
Parrain string `gorm:"column:parrain"`
PointsExtraJSON []byte `gorm:"column:points_extra"`
CreatedAt time.Time `gorm:"column:created_at"`
}
err := d.GDB.Raw(`
SELECT id, username, password, nom, prenom, telephone, command, amende, referral_balance,
COALESCE(cancellations_count, 0) as cancellations_count,
COALESCE(last_penalty_reason, '') as last_penalty_reason,
COALESCE(parrain, '') as parrain,
COALESCE(points_extra, '{}'::jsonb) as points_extra, created_at
FROM clients ORDER BY created_at DESC`).Scan(&rows).Error
FROM clients ORDER BY created_at DESC LIMIT ? OFFSET ?`, limit, offset).Scan(&rows).Error
if err != nil {
return nil, fmt.Errorf("erreur lors de la récupération des clients: %w", err)
return nil, 0, fmt.Errorf("erreur lors de la récupération des clients: %w", err)
}
var total int64
if err := d.GDB.Table("clients").Count(&total).Error; err != nil {
return nil, 0, fmt.Errorf("erreur lors du comptage des clients: %w", err)
}
clients := make([]*models.Client, 0, len(rows))
@@ -114,6 +124,8 @@ func (d *Database) GetAllClients() ([]*models.Client, error) {
Amende: row.Amende,
ReferralBalance: row.ReferralBalance,
CancellationsCount: row.CancellationsCount,
LastPenaltyReason: row.LastPenaltyReason,
Parrain: row.Parrain,
CreatedAt: row.CreatedAt,
}
client.PointsExtra = map[string]int{}
@@ -123,7 +135,7 @@ func (d *Database) GetAllClients() ([]*models.Client, error) {
clients = append(clients, client)
}
return clients, nil
return clients, total, nil
}
// UpdateClient met à jour un client existant