feat: 管理首页帖子总数统计(总数/已发布/待审核)
- PostRepo 新增 CountPostsByStatus 和 CountPending 方法 - Service 层定义 postAdminStatStore 接口 (ISP) - AdminService 注入 postRepo,新增 PostStats 结构体和 GetPostStats 方法 - AdminController.Dashboard 调用 GetPostStats 并传参到模板 - Dashboard 帖子卡片显示总数 + 已发布 + 待审核(橙色徽章) - DI 层将 AdminController 创建从 buildDepsCore 移至 buildDeps,以便注入 postRepo
This commit is contained in:
@ -8,12 +8,20 @@ import (
|
||||
|
||||
type AdminService struct {
|
||||
userRepo userAdminStore
|
||||
postRepo postAdminStatStore
|
||||
sessionManager *session.Manager
|
||||
}
|
||||
|
||||
// PostStats 帖子统计结果(管理首页用)
|
||||
type PostStats struct {
|
||||
Total int64 // 全部未删除帖子数
|
||||
Approved int64 // 已发布数
|
||||
Pending int64 // 待审核数(pending + 待审修订)
|
||||
}
|
||||
|
||||
// NewAdminService 构造函数
|
||||
func NewAdminService(userRepo userAdminStore, sm *session.Manager) *AdminService {
|
||||
return &AdminService{userRepo: userRepo, sessionManager: sm}
|
||||
func NewAdminService(userRepo userAdminStore, postRepo postAdminStatStore, sm *session.Manager) *AdminService {
|
||||
return &AdminService{userRepo: userRepo, postRepo: postRepo, sessionManager: sm}
|
||||
}
|
||||
|
||||
// ListUsersParams 用户列表查询参数
|
||||
@ -112,6 +120,23 @@ func (s *AdminService) CountUsers() (int64, error) {
|
||||
return s.userRepo.CountSearchUsers("", "", "")
|
||||
}
|
||||
|
||||
// GetPostStats 获取帖子统计(管理首页用)
|
||||
func (s *AdminService) GetPostStats() (*PostStats, error) {
|
||||
total, err := s.postRepo.CountPostsByStatus("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
approved, err := s.postRepo.CountPostsByStatus(model.PostStatusApproved)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pending, err := s.postRepo.CountPending()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &PostStats{Total: total, Approved: approved, Pending: pending}, nil
|
||||
}
|
||||
|
||||
// GetStoreMetrics 返回会话存储状态信息(管理首页用)
|
||||
func (s *AdminService) GetStoreMetrics() session.StoreMetrics {
|
||||
return s.sessionManager.GetStoreMetrics()
|
||||
|
||||
@ -47,6 +47,12 @@ type spacePostStore interface {
|
||||
FindByUserID(userID uint, offset, limit int) ([]model.Post, int64, error)
|
||||
}
|
||||
|
||||
// postAdminStatStore AdminService 所需的帖子统计接口(ISP:2 个方法)
|
||||
type postAdminStatStore interface {
|
||||
CountPostsByStatus(status string) (int64, error)
|
||||
CountPending() (int64, error)
|
||||
}
|
||||
|
||||
// postNotifier PostService 所需的通知服务接口
|
||||
type postNotifier interface {
|
||||
NotifyPostApproved(userID uint, postTitle string, postID uint)
|
||||
|
||||
Reference in New Issue
Block a user