Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions backend/internal/handler/admin/group_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/Wei-Shaw/sub2api/internal/handler/dto"
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
Expand Down Expand Up @@ -358,14 +359,43 @@ func (h *GroupHandler) GetStats(c *gin.Context) {
return
}

// Return mock data for now
// Get total API keys count for this group
var totalAPIKeys int64
_, totalAPIKeys, err = h.adminService.GetGroupAPIKeys(c.Request.Context(), groupID, 1, 1)
if err != nil {
response.ErrorFrom(c, err)
return
}

// Get total accounts count for this group
_, totalAccounts, err := h.adminService.ListAccounts(c.Request.Context(), 1, 1, "", "", "", "", groupID, "")
if err != nil {
response.ErrorFrom(c, err)
return
}

// Get usage stats (requests and cost) from dashboard service
var totalRequests int64
var totalCost float64
if h.dashboardService != nil {
stats, statsErr := h.dashboardService.GetGroupStatsWithFilters(
c.Request.Context(), time.Time{}, time.Now().UTC(),
0, 0, 0, groupID, nil, nil, nil,
)
if statsErr == nil {
for _, s := range stats {
totalRequests += s.Requests
totalCost += s.Cost
}
}
}

response.Success(c, gin.H{
"total_api_keys": 0,
"active_api_keys": 0,
"total_requests": 0,
"total_cost": 0.0,
"total_api_keys": totalAPIKeys,
"total_accounts": totalAccounts,
"total_requests": totalRequests,
"total_cost": totalCost,
})
_ = groupID // TODO: implement actual stats
}

// GetUsageSummary returns today's and cumulative cost for all groups.
Expand Down