@@ -9,14 +9,17 @@ import (
99
1010 "github.com/Wei-Shaw/sub2api/internal/handler/dto"
1111 "github.com/Wei-Shaw/sub2api/internal/pkg/response"
12+ "github.com/Wei-Shaw/sub2api/internal/pkg/timezone"
1213 "github.com/Wei-Shaw/sub2api/internal/service"
1314
1415 "github.com/gin-gonic/gin"
1516)
1617
1718// GroupHandler handles admin group management
1819type GroupHandler struct {
19- adminService service.AdminService
20+ adminService service.AdminService
21+ dashboardService * service.DashboardService
22+ groupCapacityService * service.GroupCapacityService
2023}
2124
2225type optionalLimitField struct {
@@ -69,9 +72,11 @@ func (f optionalLimitField) ToServiceInput() *float64 {
6972}
7073
7174// NewGroupHandler creates a new admin group handler
72- func NewGroupHandler (adminService service.AdminService ) * GroupHandler {
75+ func NewGroupHandler (adminService service.AdminService , dashboardService * service. DashboardService , groupCapacityService * service. GroupCapacityService ) * GroupHandler {
7376 return & GroupHandler {
74- adminService : adminService ,
77+ adminService : adminService ,
78+ dashboardService : dashboardService ,
79+ groupCapacityService : groupCapacityService ,
7580 }
7681}
7782
@@ -363,6 +368,33 @@ func (h *GroupHandler) GetStats(c *gin.Context) {
363368 _ = groupID // TODO: implement actual stats
364369}
365370
371+ // GetUsageSummary returns today's and cumulative cost for all groups.
372+ // GET /api/v1/admin/groups/usage-summary?timezone=Asia/Shanghai
373+ func (h * GroupHandler ) GetUsageSummary (c * gin.Context ) {
374+ userTZ := c .Query ("timezone" )
375+ now := timezone .NowInUserLocation (userTZ )
376+ todayStart := timezone .StartOfDayInUserLocation (now , userTZ )
377+
378+ results , err := h .dashboardService .GetGroupUsageSummary (c .Request .Context (), todayStart )
379+ if err != nil {
380+ response .Error (c , 500 , "Failed to get group usage summary" )
381+ return
382+ }
383+
384+ response .Success (c , results )
385+ }
386+
387+ // GetCapacitySummary returns aggregated capacity (concurrency/sessions/RPM) for all active groups.
388+ // GET /api/v1/admin/groups/capacity-summary
389+ func (h * GroupHandler ) GetCapacitySummary (c * gin.Context ) {
390+ results , err := h .groupCapacityService .GetAllGroupCapacity (c .Request .Context ())
391+ if err != nil {
392+ response .Error (c , 500 , "Failed to get group capacity summary" )
393+ return
394+ }
395+ response .Success (c , results )
396+ }
397+
366398// GetGroupAPIKeys handles getting API keys in a group
367399// GET /api/v1/admin/groups/:id/api-keys
368400func (h * GroupHandler ) GetGroupAPIKeys (c * gin.Context ) {
0 commit comments