Files
backend/internal/handler/admin_dashboard_handler.go
lafay 67a5660952
All checks were successful
Build Backend / build (push) Successful in 3m54s
Build Backend / build-docker (push) Successful in 1m9s
refactor: unify code formatting and improve push/search implementations
- Remove BOM from all Go source files
- Standardize import ordering and whitespace across handlers and services
- Replace PostgreSQL full-text search with ILIKE pattern matching in post and user repositories
- Enhance JPush client with TLS transport, rate limit monitoring, and simplified API
- Refactor PushService to include userID in device management methods
- Add MaxDevicesPerUser limit and extract helper functions for push payload construction
2026-04-28 14:53:04 +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)
}