@@ -333,6 +333,76 @@ func (h *DashboardHandler) GetModelStats(c *gin.Context) {
333333 })
334334}
335335
336+ // GetGroupStats handles getting group usage statistics
337+ // GET /api/v1/admin/dashboard/groups
338+ // Query params: start_date, end_date (YYYY-MM-DD), user_id, api_key_id, account_id, group_id, request_type, stream, billing_type
339+ func (h * DashboardHandler ) GetGroupStats (c * gin.Context ) {
340+ startTime , endTime := parseTimeRange (c )
341+
342+ var userID , apiKeyID , accountID , groupID int64
343+ var requestType * int16
344+ var stream * bool
345+ var billingType * int8
346+
347+ if userIDStr := c .Query ("user_id" ); userIDStr != "" {
348+ if id , err := strconv .ParseInt (userIDStr , 10 , 64 ); err == nil {
349+ userID = id
350+ }
351+ }
352+ if apiKeyIDStr := c .Query ("api_key_id" ); apiKeyIDStr != "" {
353+ if id , err := strconv .ParseInt (apiKeyIDStr , 10 , 64 ); err == nil {
354+ apiKeyID = id
355+ }
356+ }
357+ if accountIDStr := c .Query ("account_id" ); accountIDStr != "" {
358+ if id , err := strconv .ParseInt (accountIDStr , 10 , 64 ); err == nil {
359+ accountID = id
360+ }
361+ }
362+ if groupIDStr := c .Query ("group_id" ); groupIDStr != "" {
363+ if id , err := strconv .ParseInt (groupIDStr , 10 , 64 ); err == nil {
364+ groupID = id
365+ }
366+ }
367+ if requestTypeStr := strings .TrimSpace (c .Query ("request_type" )); requestTypeStr != "" {
368+ parsed , err := service .ParseUsageRequestType (requestTypeStr )
369+ if err != nil {
370+ response .BadRequest (c , err .Error ())
371+ return
372+ }
373+ value := int16 (parsed )
374+ requestType = & value
375+ } else if streamStr := c .Query ("stream" ); streamStr != "" {
376+ if streamVal , err := strconv .ParseBool (streamStr ); err == nil {
377+ stream = & streamVal
378+ } else {
379+ response .BadRequest (c , "Invalid stream value, use true or false" )
380+ return
381+ }
382+ }
383+ if billingTypeStr := c .Query ("billing_type" ); billingTypeStr != "" {
384+ if v , err := strconv .ParseInt (billingTypeStr , 10 , 8 ); err == nil {
385+ bt := int8 (v )
386+ billingType = & bt
387+ } else {
388+ response .BadRequest (c , "Invalid billing_type" )
389+ return
390+ }
391+ }
392+
393+ stats , err := h .dashboardService .GetGroupStatsWithFilters (c .Request .Context (), startTime , endTime , userID , apiKeyID , accountID , groupID , requestType , stream , billingType )
394+ if err != nil {
395+ response .Error (c , 500 , "Failed to get group statistics" )
396+ return
397+ }
398+
399+ response .Success (c , gin.H {
400+ "groups" : stats ,
401+ "start_date" : startTime .Format ("2006-01-02" ),
402+ "end_date" : endTime .Add (- 24 * time .Hour ).Format ("2006-01-02" ),
403+ })
404+ }
405+
336406// GetAPIKeyUsageTrend handles getting API key usage trend data
337407// GET /api/v1/admin/dashboard/api-keys-trend
338408// Query params: start_date, end_date (YYYY-MM-DD), granularity (day/hour), limit (default 5)
0 commit comments