- 所有Handler方法使用标准{code:0,message:"success",data:...}响应格式
- 修复Cursor分页响应包装(GetAllDevices,GetLoginLogs,ListUsers等)
- 修复AuthHandler和SMSHandler认证方法响应格式
- 修复operation_log.go admin用户operation_type前缀问题
- 修复DashboardPage嵌套stats结构
- 修复LoginLogsPage reset功能stale closure问题
- 修复UsersPage批量操作API调用
- 修复多个前端测试(mock格式、按钮选择、断言逻辑)
- 添加OAuth测试域名白名单
- 新增代码审查流程文档
38 lines
1.0 KiB
Go
38 lines
1.0 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}
|
|
}
|
|
|
|
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, "data": stats})
|
|
}
|
|
|
|
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, "data": stats})
|
|
}
|