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}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "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
|
|
|
}
|