Added @Summary, @Description, @Tags, @Param, @Success, @Failure, @Router annotations to all major handler endpoints for OpenAPI/Swagger auto-generation. Covers 86 annotations across: - auth_handler.go (25): all auth endpoints - user_handler.go (14): CRUD + roles + admin management - device_handler.go (13): device CRUD + trust management - role_handler.go (8): role CRUD + permissions - custom_field_handler.go (7): field CRUD + user values - permission_handler.go (7): permission CRUD + tree - log_handler.go (3): login/operation logs - captcha_handler.go (3): generate/verify - stats_handler.go (2): dashboard + user stats - avatar_handler.go (1): upload avatar - totp_handler.go (1): totp status - password_reset_handler.go (1): forgot password Partially addresses P2: missing Swagger annotations (PRODUCTION_GAP_ANALYSIS_2026-04-08)
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/user-management-system/internal/service"
|
|
)
|
|
|
|
// StatsHandler handles statistics requests
|
|
type StatsHandler struct {
|
|
statsService *service.StatsService
|
|
}
|
|
|
|
// NewStatsHandler creates a new StatsHandler
|
|
func NewStatsHandler(statsService *service.StatsService) *StatsHandler {
|
|
return &StatsHandler{statsService: statsService}
|
|
}
|
|
|
|
// GetDashboard 获取仪表盘统计
|
|
// @Summary 获取仪表盘统计
|
|
// @Description 获取系统仪表盘统计数据(仅管理员)
|
|
// @Tags 统计
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Success 200 {object} Response{data=service.DashboardStats} "仪表盘数据"
|
|
// @Failure 403 {object} Response "无权限"
|
|
// @Failure 500 {object} Response "服务器错误"
|
|
// @Router /api/v1/admin/stats/dashboard [get]
|
|
func (h *StatsHandler) GetDashboard(c *gin.Context) {
|
|
stats, err := h.statsService.GetDashboardStats(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": "获取仪表盘数据失败"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "success", "data": stats})
|
|
}
|
|
|
|
// GetUserStats 获取用户统计
|
|
// @Summary 获取用户统计
|
|
// @Description 获取用户统计数据(仅管理员)
|
|
// @Tags 统计
|
|
// @Produce json
|
|
// @Security BearerAuth
|
|
// @Success 200 {object} Response{data=service.UserStats} "用户统计数据"
|
|
// @Failure 403 {object} Response "无权限"
|
|
// @Failure 500 {object} Response "服务器错误"
|
|
// @Router /api/v1/admin/stats/users [get]
|
|
func (h *StatsHandler) GetUserStats(c *gin.Context) {
|
|
stats, err := h.statsService.GetUserStats(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": "获取用户统计失败"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "success", "data": stats})
|
|
}
|