remove mock group stats endpoint
Some checks failed
CI / test (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Security Scan / backend-security (push) Has been cancelled
Security Scan / frontend-security (push) Has been cancelled

This commit is contained in:
2026-04-20 15:57:39 +08:00
parent b3f112005e
commit 8ce3dc4c73
5 changed files with 6 additions and 43 deletions

View File

@@ -36,7 +36,6 @@ func setupAdminRouter() (*gin.Engine, *stubAdminService) {
router.POST("/api/v1/admin/groups", groupHandler.Create) router.POST("/api/v1/admin/groups", groupHandler.Create)
router.PUT("/api/v1/admin/groups/:id", groupHandler.Update) router.PUT("/api/v1/admin/groups/:id", groupHandler.Update)
router.DELETE("/api/v1/admin/groups/:id", groupHandler.Delete) router.DELETE("/api/v1/admin/groups/:id", groupHandler.Delete)
router.GET("/api/v1/admin/groups/:id/stats", groupHandler.GetStats)
router.GET("/api/v1/admin/groups/:id/api-keys", groupHandler.GetGroupAPIKeys) router.GET("/api/v1/admin/groups/:id/api-keys", groupHandler.GetGroupAPIKeys)
router.GET("/api/v1/admin/proxies", proxyHandler.List) router.GET("/api/v1/admin/proxies", proxyHandler.List)
@@ -147,7 +146,7 @@ func TestGroupHandlerEndpoints(t *testing.T) {
rec = httptest.NewRecorder() rec = httptest.NewRecorder()
req = httptest.NewRequest(http.MethodGet, "/api/v1/admin/groups/2/stats", nil) req = httptest.NewRequest(http.MethodGet, "/api/v1/admin/groups/2/stats", nil)
router.ServeHTTP(rec, req) router.ServeHTTP(rec, req)
require.Equal(t, http.StatusOK, rec.Code) require.Equal(t, http.StatusNotFound, rec.Code)
rec = httptest.NewRecorder() rec = httptest.NewRecorder()
req = httptest.NewRequest(http.MethodGet, "/api/v1/admin/groups/2/api-keys", nil) req = httptest.NewRequest(http.MethodGet, "/api/v1/admin/groups/2/api-keys", nil)
@@ -279,6 +278,10 @@ func TestDeprecatedMockAdminEndpointsNotRegistered(t *testing.T) {
name string name string
url string url string
}{ }{
{
name: "group stats",
url: "/api/v1/admin/groups/2/stats",
},
{ {
name: "user usage", name: "user usage",
url: "/api/v1/admin/users/1/usage?period=today", url: "/api/v1/admin/users/1/usage?period=today",

View File

@@ -341,25 +341,6 @@ func (h *GroupHandler) Delete(c *gin.Context) {
response.Success(c, gin.H{"message": "Group deleted successfully"}) response.Success(c, gin.H{"message": "Group deleted successfully"})
} }
// GetStats handles getting group statistics
// GET /api/v1/admin/groups/:id/stats
func (h *GroupHandler) GetStats(c *gin.Context) {
groupID, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
response.BadRequest(c, "Invalid group ID")
return
}
// Return mock data for now
response.Success(c, gin.H{
"total_api_keys": 0,
"active_api_keys": 0,
"total_requests": 0,
"total_cost": 0.0,
})
_ = groupID // TODO: implement actual stats
}
// GetUsageSummary returns today's and cumulative cost for all groups. // GetUsageSummary returns today's and cumulative cost for all groups.
// GET /api/v1/admin/groups/usage-summary?timezone=Asia/Shanghai // GET /api/v1/admin/groups/usage-summary?timezone=Asia/Shanghai
func (h *GroupHandler) GetUsageSummary(c *gin.Context) { func (h *GroupHandler) GetUsageSummary(c *gin.Context) {

View File

@@ -257,7 +257,6 @@ func registerGroupRoutes(admin *gin.RouterGroup, h *handler.Handlers) {
groups.POST("", h.Admin.Group.Create) groups.POST("", h.Admin.Group.Create)
groups.PUT("/:id", h.Admin.Group.Update) groups.PUT("/:id", h.Admin.Group.Update)
groups.DELETE("/:id", h.Admin.Group.Delete) groups.DELETE("/:id", h.Admin.Group.Delete)
groups.GET("/:id/stats", h.Admin.Group.GetStats)
groups.GET("/:id/rate-multipliers", h.Admin.Group.GetGroupRateMultipliers) groups.GET("/:id/rate-multipliers", h.Admin.Group.GetGroupRateMultipliers)
groups.PUT("/:id/rate-multipliers", h.Admin.Group.BatchSetGroupRateMultipliers) groups.PUT("/:id/rate-multipliers", h.Admin.Group.BatchSetGroupRateMultipliers)
groups.DELETE("/:id/rate-multipliers", h.Admin.Group.ClearGroupRateMultipliers) groups.DELETE("/:id/rate-multipliers", h.Admin.Group.ClearGroupRateMultipliers)

View File

@@ -29,6 +29,7 @@ func TestRegisterAdminRoutes_OmitsDeprecatedMockEndpoints(t *testing.T) {
deprecatedRoutes := []string{ deprecatedRoutes := []string{
"GET /api/v1/admin/dashboard/realtime", "GET /api/v1/admin/dashboard/realtime",
"GET /api/v1/admin/groups/:id/stats",
"GET /api/v1/admin/users/:id/usage", "GET /api/v1/admin/users/:id/usage",
"GET /api/v1/admin/proxies/:id/stats", "GET /api/v1/admin/proxies/:id/stats",
"GET /api/v1/admin/redeem-codes/stats", "GET /api/v1/admin/redeem-codes/stats",

View File

@@ -117,26 +117,6 @@ export async function toggleStatus(id: number, status: 'active' | 'inactive'): P
return update(id, { status }) return update(id, { status })
} }
/**
* Get group statistics
* @param id - Group ID
* @returns Group usage statistics
*/
export async function getStats(id: number): Promise<{
total_api_keys: number
active_api_keys: number
total_requests: number
total_cost: number
}> {
const { data } = await apiClient.get<{
total_api_keys: number
active_api_keys: number
total_requests: number
total_cost: number
}>(`/admin/groups/${id}/stats`)
return data
}
/** /**
* Get API keys in a group * Get API keys in a group
* @param id - Group ID * @param id - Group ID
@@ -257,7 +237,6 @@ export const groupsAPI = {
update, update,
delete: deleteGroup, delete: deleteGroup,
toggleStatus, toggleStatus,
getStats,
getGroupApiKeys, getGroupApiKeys,
getGroupRateMultipliers, getGroupRateMultipliers,
clearGroupRateMultipliers, clearGroupRateMultipliers,