From c834e40e8312668f31d9a1cd9a7653fc9be2e3ab Mon Sep 17 00:00:00 2001
From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com>
Date: Thu, 21 May 2026 10:25:18 -0500
Subject: [PATCH] fix(servidor-dashboard): show DB connection count on server
cards
- GetServidor: query conx_count per server with GROUP BY and attach to response
- servidor_dashboard.html: use conx_count from API (fallback to _conexiones.length)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
resources/views/servidor_dashboard.html | 2 +-
rest/controllers/servidor_controller.go | 35 ++++++++++++++++++++++++-
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/resources/views/servidor_dashboard.html b/resources/views/servidor_dashboard.html
index 3697cad..34b35f6 100644
--- a/resources/views/servidor_dashboard.html
+++ b/resources/views/servidor_dashboard.html
@@ -77,7 +77,7 @@
-
+
conexiones BD
diff --git a/rest/controllers/servidor_controller.go b/rest/controllers/servidor_controller.go
index 8416a38..3e55cd9 100755
--- a/rest/controllers/servidor_controller.go
+++ b/rest/controllers/servidor_controller.go
@@ -63,9 +63,42 @@ func GetServidor(c *fiber.Ctx) error {
"error": err.Error(),
})
}
+
+ // Build connection count map per server
+ type conxCount struct {
+ ServidorID uint `gorm:"column:servidor_id"`
+ Count int64 `gorm:"column:count"`
+ }
+ var counts []conxCount
+ serverIDs := make([]uint, len(records))
+ for i, s := range records {
+ serverIDs[i] = s.ID
+ }
+ if len(serverIDs) > 0 {
+ app.Http.Database.DB.Table("conx_db").
+ Select("servidor_id, count(*) as count").
+ Where("servidor_id IN ? AND deleted_at IS NULL", serverIDs).
+ Group("servidor_id").
+ Scan(&counts)
+ }
+ countMap := make(map[uint]int64)
+ for _, cc := range counts {
+ countMap[cc.ServidorID] = cc.Count
+ }
+
+ // Attach conx_count to each record
+ type servidorWithCount struct {
+ models.Servidor
+ ConxCount int64 `json:"conx_count"`
+ }
+ enriched := make([]servidorWithCount, len(records))
+ for i, s := range records {
+ enriched[i] = servidorWithCount{Servidor: s, ConxCount: countMap[s.ID]}
+ }
+
totalPages := int(math.Ceil(float64(total) / float64(limit)))
return c.JSON(fiber.Map{
- "registros": records,
+ "registros": enriched,
"total": total,
"totalPages": totalPages,
"page": page,