chore: build
This commit is contained in:
@@ -511,7 +511,21 @@ func GetAllUsers(c *gin.Context) {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "Accès réservé aux livreurs et aux administrateurs"})
|
||||
return
|
||||
}
|
||||
users, err := database.GetAllUsers()
|
||||
|
||||
limit := 100
|
||||
offset := 0
|
||||
if limitStr := c.Query("limit"); limitStr != "" {
|
||||
if l, err := strconv.Atoi(limitStr); err == nil && l > 0 && l <= 100 {
|
||||
limit = l
|
||||
}
|
||||
}
|
||||
if offsetStr := c.Query("offset"); offsetStr != "" {
|
||||
if o, err := strconv.Atoi(offsetStr); err == nil && o >= 0 {
|
||||
offset = o
|
||||
}
|
||||
}
|
||||
|
||||
users, total, err := database.GetAllUsers(limit, offset)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("❌ [GET_ALL_USERS] Erreur: %v", err)
|
||||
@@ -528,11 +542,12 @@ func GetAllUsers(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
log.Printf("✅ [GET_ALL_USERS] %d users récupérés", len(sanitized))
|
||||
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{
|
||||
"users": sanitized,
|
||||
"count": len(sanitized),
|
||||
"users": sanitized,
|
||||
"count": total,
|
||||
"has_more": int64(offset+len(users)) < total,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -549,13 +564,39 @@ func GetAllDeliveryMen(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur récupération"})
|
||||
return
|
||||
}
|
||||
usernames := make([]string, len(users))
|
||||
for i, u := range users {
|
||||
usernames[i] = u.Username
|
||||
}
|
||||
detailsByUsername := database.GetDeliveryPersonsDetailsBatch(usernames)
|
||||
|
||||
var sanitized []gin.H
|
||||
for _, u := range users {
|
||||
sanitized = append(sanitized, gin.H{
|
||||
"id": u.ID,
|
||||
"username": u.Username,
|
||||
"role": u.Role,
|
||||
})
|
||||
det := detailsByUsername[u.Username]
|
||||
if det == nil {
|
||||
det = &db.DeliveryPersonDetails{Status: "offline"}
|
||||
}
|
||||
entry := gin.H{
|
||||
"id": u.ID,
|
||||
"username": u.Username,
|
||||
"role": u.Role,
|
||||
"status": det.Status,
|
||||
"queue_size": det.QueueSize,
|
||||
"total_deliveries": det.TotalDeliveries,
|
||||
"completed_deliveries": det.CompletedDeliveries,
|
||||
"pending_deliveries": det.PendingDeliveries,
|
||||
}
|
||||
if det.CurrentCommand != 0 {
|
||||
entry["current_command"] = det.CurrentCommand
|
||||
} else {
|
||||
entry["current_command"] = nil
|
||||
}
|
||||
if det.HasLocation {
|
||||
entry["location"] = gin.H{"latitude": det.Latitude, "longitude": det.Longitude}
|
||||
} else {
|
||||
entry["location"] = nil
|
||||
}
|
||||
sanitized = append(sanitized, entry)
|
||||
}
|
||||
|
||||
log.Printf("✅ [GET_ALL_USERS] %d users récupérés", len(sanitized))
|
||||
@@ -575,16 +616,33 @@ func GetAllClients(c *gin.Context) {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "Accès réservé aux livreurs et aux administrateurs"})
|
||||
return
|
||||
}
|
||||
clients, err := database.GetAllClients()
|
||||
|
||||
limit := 100
|
||||
offset := 0
|
||||
if limitStr := c.Query("limit"); limitStr != "" {
|
||||
if l, err := strconv.Atoi(limitStr); err == nil && l > 0 && l <= 100 {
|
||||
limit = l
|
||||
}
|
||||
}
|
||||
if offsetStr := c.Query("offset"); offsetStr != "" {
|
||||
if o, err := strconv.Atoi(offsetStr); err == nil && o >= 0 {
|
||||
offset = o
|
||||
}
|
||||
}
|
||||
|
||||
clients, total, err := database.GetAllClients(limit, offset)
|
||||
if err != nil {
|
||||
log.Printf("❌ [GET_ALL_CLIENTS] Erreur: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur récupération"})
|
||||
return
|
||||
}
|
||||
|
||||
limited := rateLimitedClients(clients)
|
||||
|
||||
var sanitized []gin.H
|
||||
for _, cl := range clients {
|
||||
sanitized = append(sanitized, gin.H{
|
||||
"rate_limited": limited[cl.Username],
|
||||
"id": cl.ID,
|
||||
"username": cl.Username,
|
||||
"nom": cl.Nom,
|
||||
@@ -596,14 +654,16 @@ func GetAllClients(c *gin.Context) {
|
||||
"cancellations_count": cl.CancellationsCount,
|
||||
"last_penalty_reason": cl.LastPenaltyReason,
|
||||
"referral_balance": cl.ReferralBalance,
|
||||
"parrain": cl.Parrain,
|
||||
})
|
||||
}
|
||||
|
||||
log.Printf("✅ [GET_ALL_CLIENTS] %d clients récupérés", len(sanitized))
|
||||
log.Printf("✅ [GET_ALL_CLIENTS] %d clients récupérés (offset=%d, total=%d)", len(sanitized), offset, total)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"clients": sanitized,
|
||||
"count": len(sanitized),
|
||||
"clients": sanitized,
|
||||
"count": total,
|
||||
"has_more": int64(offset+len(clients)) < total,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user