Files
backend/internal/handler/admin_dashboard_handler.go
lafay 2f584c1f2c
All checks were successful
Build Backend / build (push) Successful in 5m10s
Build Backend / build-docker (push) Successful in 2m22s
This is a breaking change that renames the entire project from "Carrot BBS" to "WithYou".
The Go module name has been changed from `carrot_bbs` to `with_you`, which requires
all import paths to be updated throughout the codebase and by external consumers.

BREAKING CHANGE: Module name changed from carrot_bbs to with_you. All imports
and dependencies must be updated from carrot_bbs/* to with_you/*.
2026-04-22 16:01:59 +08:00

91 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import (
"strconv"
"with_you/internal/pkg/response"
"with_you/internal/service"
"github.com/gin-gonic/gin"
)
// AdminDashboardHandler 管理端仪表盘处理器
type AdminDashboardHandler struct {
dashboardService service.AdminDashboardService
}
// NewAdminDashboardHandler 创建管理端仪表盘处理器
func NewAdminDashboardHandler(dashboardService service.AdminDashboardService) *AdminDashboardHandler {
return &AdminDashboardHandler{
dashboardService: dashboardService,
}
}
// GetStats 获取统计数据
// GET /api/v1/admin/dashboard/stats
func (h *AdminDashboardHandler) GetStats(c *gin.Context) {
stats, err := h.dashboardService.GetStats(c.Request.Context())
if err != nil {
response.InternalServerError(c, "failed to get dashboard stats")
return
}
response.Success(c, stats)
}
// GetUserActivityTrend 获取用户活跃度趋势
// GET /api/v1/admin/dashboard/user-activity
func (h *AdminDashboardHandler) GetUserActivityTrend(c *gin.Context) {
// 解析天数参数默认7天限制在1-30天
days, _ := strconv.Atoi(c.DefaultQuery("days", "7"))
days = min(max(days, 1), 30)
trend, err := h.dashboardService.GetUserActivityTrend(c.Request.Context(), days)
if err != nil {
response.InternalServerError(c, "failed to get user activity trend")
return
}
response.Success(c, trend)
}
// GetContentStats 获取内容统计
// GET /api/v1/admin/dashboard/content-stats
func (h *AdminDashboardHandler) GetContentStats(c *gin.Context) {
stats, err := h.dashboardService.GetContentStats(c.Request.Context())
if err != nil {
response.InternalServerError(c, "failed to get content stats")
return
}
response.Success(c, stats)
}
// GetPendingContent 获取待审核内容
// GET /api/v1/admin/dashboard/pending-content
func (h *AdminDashboardHandler) GetPendingContent(c *gin.Context) {
// 解析limit参数默认10条限制在1-50条
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
limit = min(max(limit, 1), 50)
content, err := h.dashboardService.GetPendingContent(c.Request.Context(), limit)
if err != nil {
response.InternalServerError(c, "failed to get pending content")
return
}
response.Success(c, content)
}
// GetOnlineUsers 获取在线用户数
// GET /api/v1/admin/dashboard/online-users
func (h *AdminDashboardHandler) GetOnlineUsers(c *gin.Context) {
onlineUsers, err := h.dashboardService.GetOnlineUsers(c.Request.Context())
if err != nil {
response.InternalServerError(c, "failed to get online users count")
return
}
response.Success(c, onlineUsers)
}