feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
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}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-11 21:23:52 +08:00
|
|
|
// 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]
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
func (h *StatsHandler) GetDashboard(c *gin.Context) {
|
2026-04-08 20:06:54 +08:00
|
|
|
stats, err := h.statsService.GetDashboardStats(c.Request.Context())
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": "获取仪表盘数据失败"})
|
|
|
|
|
return
|
|
|
|
|
}
|
fix: unify handler response format in multiple handlers
- captcha_handler.go: Fix GenerateCaptcha/VerifyCaptcha to use {code, message, data}
- password_reset_handler.go: Fix all error responses to use {code, message}
- settings_handler.go: Add missing "code" and "message" fields
- sms_handler.go: Fix error responses to use {code, message}
- sso_handler.go: Fix all error responses to use {code, message, data}
- stats_handler.go: Add missing "message" field in success responses
- theme_handler.go: Fix error responses to use {code, message}
- totp_handler.go: Fix all responses to use {code, message, data}
Standardize all JSON responses to {code: 0, message: "success", data: ...} for success
and {code: XXX, message: "..."} for errors.
2026-04-11 13:06:58 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "success", "data": stats})
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-11 21:23:52 +08:00
|
|
|
// 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]
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
func (h *StatsHandler) GetUserStats(c *gin.Context) {
|
2026-04-08 20:06:54 +08:00
|
|
|
stats, err := h.statsService.GetUserStats(c.Request.Context())
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": "获取用户统计失败"})
|
|
|
|
|
return
|
|
|
|
|
}
|
fix: unify handler response format in multiple handlers
- captcha_handler.go: Fix GenerateCaptcha/VerifyCaptcha to use {code, message, data}
- password_reset_handler.go: Fix all error responses to use {code, message}
- settings_handler.go: Add missing "code" and "message" fields
- sms_handler.go: Fix error responses to use {code, message}
- sso_handler.go: Fix all error responses to use {code, message, data}
- stats_handler.go: Add missing "message" field in success responses
- theme_handler.go: Fix error responses to use {code, message}
- totp_handler.go: Fix all responses to use {code, message, data}
Standardize all JSON responses to {code: 0, message: "success", data: ...} for success
and {code: XXX, message: "..."} for errors.
2026-04-11 13:06:58 +08:00
|
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "success", "data": stats})
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
}
|