chore: build
Backend - Build & Lint / build (push) Successful in 32m22s
Frontend Admin - EAS Build / build (push) Successful in 1h39m14s

This commit is contained in:
Cameron Foussard
2026-11-03 09:12:36 +01:00
parent 0a18460f13
commit ae89d995d2
5 changed files with 98 additions and 15 deletions
+33
View File
@@ -25,6 +25,39 @@ func (d *Database) GetAllUsers(limit, offset int) ([]*models.User, int64, error)
return users, total, nil
}
// UserCounts contient les totaux globaux (non paginés) affichés côté admin.
// Les usernames présents à la fois dans users et clients ne sont comptés
// qu'une fois, comme dans la liste fusionnée du front.
type UserCounts struct {
All int64 `json:"all" gorm:"column:all_count"`
Client int64 `json:"client" gorm:"column:client_count"`
Livreur int64 `json:"livreur" gorm:"column:livreur_count"`
Cabine int64 `json:"cabine" gorm:"column:cabine_count"`
Admin int64 `json:"admin" gorm:"column:admin_count"`
}
func (d *Database) GetUserCounts() (*UserCounts, error) {
var counts UserCounts
err := d.GDB.Raw(`
WITH merged AS (
SELECT username, role FROM users
UNION
SELECT c.username, 'client' AS role FROM clients c
WHERE NOT EXISTS (SELECT 1 FROM users u WHERE u.username = c.username)
)
SELECT
COUNT(DISTINCT username) AS all_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'client') AS client_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'livreur') AS livreur_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'cabine') AS cabine_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'admin') AS admin_count
FROM merged`).Scan(&counts).Error
if err != nil {
return nil, fmt.Errorf("erreur lors du comptage des utilisateurs par rôle: %w", err)
}
return &counts, nil
}
func (d *Database) GetAllDeliveryMen() ([]*models.User, error) {
var users []*models.User
if err := d.GDB.Where("role = ?", "livreur").Limit(100).Find(&users).Error; err != nil {
+13 -2
View File
@@ -544,11 +544,22 @@ func GetAllUsers(c *gin.Context) {
log.Printf("✅ [GET_ALL_USERS] %d users récupérés (offset=%d, total=%d)", len(sanitized), offset, total)
c.JSON(http.StatusOK, gin.H{
resp := gin.H{
"users": sanitized,
"count": total,
"has_more": int64(offset+len(users)) < total,
})
}
// Totaux globaux par rôle (indépendants de la pagination) : uniquement
// sur la première page, c'est là que le front les lit.
if offset == 0 {
if counts, err := database.GetUserCounts(); err != nil {
log.Printf("⚠️ [GET_ALL_USERS] Comptage par rôle impossible: %v", err)
} else {
resp["counts"] = counts
}
}
c.JSON(http.StatusOK, resp)
}
func GetAllDeliveryMen(c *gin.Context) {