package handlers import ( "net/http" "github.com/gin-gonic/gin" "github.com/niangaodev/art-code/repositories" ) // 仪表盘数据处理函数 func AdminGetDashboardStats(c *gin.Context) { // 获取统计数据 userCount, err := repositories.GetUserCount() if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get user count"}) return } postCount, err := repositories.GetPostCount() if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get post count"}) return } workCount, err := repositories.GetWorkCount() if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get work count"}) return } snippetCount, err := repositories.GetSnippetCount() if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get snippet count"}) return } // 构建响应 stats := gin.H{ "users": userCount, "posts": postCount, "works": workCount, "snippets": snippetCount, } c.JSON(http.StatusOK, stats) }