chore: build
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user