remove deprecated mock admin endpoints

This commit is contained in:
2026-04-20 13:05:44 +08:00
parent ed642e8769
commit b3f112005e
13 changed files with 68 additions and 198 deletions

View File

@@ -213,7 +213,6 @@ func registerDashboardRoutes(admin *gin.RouterGroup, h *handler.Handlers) {
{
dashboard.GET("/snapshot-v2", h.Admin.Dashboard.GetSnapshotV2)
dashboard.GET("/stats", h.Admin.Dashboard.GetStats)
dashboard.GET("/realtime", h.Admin.Dashboard.GetRealtimeMetrics)
dashboard.GET("/trend", h.Admin.Dashboard.GetUsageTrend)
dashboard.GET("/models", h.Admin.Dashboard.GetModelStats)
dashboard.GET("/groups", h.Admin.Dashboard.GetGroupStats)
@@ -237,7 +236,6 @@ func registerUserManagementRoutes(admin *gin.RouterGroup, h *handler.Handlers) {
users.DELETE("/:id", h.Admin.User.Delete)
users.POST("/:id/balance", h.Admin.User.UpdateBalance)
users.GET("/:id/api-keys", h.Admin.User.GetUserAPIKeys)
users.GET("/:id/usage", h.Admin.User.GetUserUsage)
users.GET("/:id/balance-history", h.Admin.User.GetBalanceHistory)
users.POST("/:id/replace-group", h.Admin.User.ReplaceGroup)
@@ -370,7 +368,6 @@ func registerProxyRoutes(admin *gin.RouterGroup, h *handler.Handlers) {
proxies.DELETE("/:id", h.Admin.Proxy.Delete)
proxies.POST("/:id/test", h.Admin.Proxy.Test)
proxies.POST("/:id/quality-check", h.Admin.Proxy.CheckQuality)
proxies.GET("/:id/stats", h.Admin.Proxy.GetStats)
proxies.GET("/:id/accounts", h.Admin.Proxy.GetProxyAccounts)
proxies.POST("/batch-delete", h.Admin.Proxy.BatchDelete)
proxies.POST("/batch", h.Admin.Proxy.BatchCreate)
@@ -381,7 +378,6 @@ func registerRedeemCodeRoutes(admin *gin.RouterGroup, h *handler.Handlers) {
codes := admin.Group("/redeem-codes")
{
codes.GET("", h.Admin.Redeem.List)
codes.GET("/stats", h.Admin.Redeem.GetStats)
codes.GET("/export", h.Admin.Redeem.Export)
codes.GET("/:id", h.Admin.Redeem.GetByID)
codes.POST("/create-and-redeem", h.Admin.Redeem.CreateAndRedeem)

View File

@@ -0,0 +1,41 @@
package routes
import (
"testing"
"github.com/Wei-Shaw/sub2api/internal/handler"
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
)
func TestRegisterAdminRoutes_OmitsDeprecatedMockEndpoints(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
v1 := engine.Group("/api/v1")
adminAuth := middleware.AdminAuthMiddleware(func(c *gin.Context) {
c.Next()
})
RegisterAdminRoutes(v1, &handler.Handlers{
Admin: &handler.AdminHandlers{},
}, adminAuth)
routesByMethodAndPath := make(map[string]struct{})
for _, route := range engine.Routes() {
routesByMethodAndPath[route.Method+" "+route.Path] = struct{}{}
}
deprecatedRoutes := []string{
"GET /api/v1/admin/dashboard/realtime",
"GET /api/v1/admin/users/:id/usage",
"GET /api/v1/admin/proxies/:id/stats",
"GET /api/v1/admin/redeem-codes/stats",
}
for _, route := range deprecatedRoutes {
_, exists := routesByMethodAndPath[route]
require.Falsef(t, exists, "deprecated mock route should not be registered: %s", route)
}
}