- PostRepo 新增 CountPostsByStatus 和 CountPending 方法 - Service 层定义 postAdminStatStore 接口 (ISP) - AdminService 注入 postRepo,新增 PostStats 结构体和 GetPostStats 方法 - AdminController.Dashboard 调用 GetPostStats 并传参到模板 - Dashboard 帖子卡片显示总数 + 已发布 + 待审核(橙色徽章) - DI 层将 AdminController 创建从 buildDepsCore 移至 buildDeps,以便注入 postRepo
61 lines
2.2 KiB
Go
61 lines
2.2 KiB
Go
package service
|
||
|
||
import "metazone.cc/metalab/internal/model"
|
||
|
||
// userAuthStore AuthService 所需的最小仓储接口(ISP:7 个方法)
|
||
type userAuthStore interface {
|
||
ExistsByEmail(email string) (bool, error)
|
||
Create(user *model.User) error
|
||
FindByEmail(email string) (*model.User, error)
|
||
FindByID(id uint) (*model.User, error)
|
||
Update(user *model.User) error
|
||
ExistsByUsername(username string) (bool, error)
|
||
}
|
||
|
||
// userAdminStore AdminService 所需的最小仓储接口(ISP:7 个方法)
|
||
type userAdminStore interface {
|
||
CountSearchUsers(keyword, role, status string) (int64, error)
|
||
SearchUsers(keyword, role, status string, offset, limit int) ([]model.User, error)
|
||
FindByIDUnscoped(userID uint) (*model.User, error)
|
||
UpdateStatus(uid uint, status string) error
|
||
SoftDelete(uid uint) error
|
||
Restore(uid uint) error
|
||
ExistsByEmailExclude(email string, excludeUID uint) (bool, error)
|
||
}
|
||
|
||
// postStore PostService 所需的最小仓储接口
|
||
type postStore interface {
|
||
Create(post *model.Post) error
|
||
FindByID(id uint) (*model.Post, error)
|
||
FindByIDWithAuthor(id uint) (*model.Post, error)
|
||
FindPageable(keyword string, offset, limit int) ([]model.Post, int64, error)
|
||
FindAdminPageable(keyword, status string, offset, limit int) ([]model.Post, int64, error)
|
||
FindByUserIDAndStatus(userID uint, status string, offset, limit int) ([]model.Post, int64, error)
|
||
FindPendingRevisions(keyword string, offset, limit int) ([]model.Post, int64, error)
|
||
Update(post *model.Post) error
|
||
SoftDelete(id uint) error
|
||
Restore(id uint) error
|
||
}
|
||
|
||
// spaceUserStore SpaceService 所需的最小用户仓储接口
|
||
type spaceUserStore interface {
|
||
FindByID(id uint) (*model.User, error)
|
||
}
|
||
|
||
// spacePostStore SpaceService 所需的最小帖子仓储接口
|
||
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)
|
||
NotifyPostRejected(userID uint, postTitle, reason string, postID uint)
|
||
}
|