feat: 定时发布系统 — Phase 5 完成
- Post ScheduledAt 字段 - Scheduler goroutine 每分钟扫描到期文章 - Create/Update 校验最短 30min 定时 - Approve 审核晚于定时则即时发布 - public 列表+空间页过滤未到期文章 - 写文章页 datetime-local 选择器(min=now+30min) - AutoMigrate 追加新表
This commit is contained in:
@ -62,27 +62,37 @@ func (r *PostRepo) buildQuery(keyword, status string) *gorm.DB {
|
||||
return query
|
||||
}
|
||||
|
||||
// FindPageable 分页查询帖子列表(仅 approved 状态,关键词模糊搜索标题,过滤私密)
|
||||
// FindPageable 分页查询帖子列表(仅 approved + 公开 + 已到期,定时发布未到期的不可见)
|
||||
func (r *PostRepo) FindPageable(keyword string, offset, limit int) ([]model.Post, int64, error) {
|
||||
query := r.buildQuery(keyword, model.PostStatusApproved).
|
||||
Where("posts.visibility = ?", model.VisibilityPublic)
|
||||
Where("posts.visibility = ?", model.VisibilityPublic).
|
||||
Where("posts.scheduled_at IS NULL OR posts.scheduled_at <= NOW()")
|
||||
return r.pageResults(query, offset, limit)
|
||||
}
|
||||
|
||||
// FindAdminPageable 管理后台分页查询(全状态筛选,待审置顶,管理可见私密)
|
||||
// FindAdminPageable 管理后台分页查询(全状态筛选,待审置顶,管理可见私密和定时待发)
|
||||
func (r *PostRepo) FindAdminPageable(keyword, status string, offset, limit int) ([]model.Post, int64, error) {
|
||||
query := r.buildQuery(keyword, status)
|
||||
return r.pageResultsAdmin(query, offset, limit)
|
||||
}
|
||||
|
||||
// FindByUserID 分页查询某用户发布的帖子(仅 approved + 公开,含作者用户名)
|
||||
// FindByUserID 分页查询某用户发布的帖子(仅 approved + 公开 + 已到期,含作者用户名)
|
||||
func (r *PostRepo) FindByUserID(userID uint, offset, limit int) ([]model.Post, int64, error) {
|
||||
query := r.buildQuery("", model.PostStatusApproved).
|
||||
Where("posts.user_id = ?", userID).
|
||||
Where("posts.visibility = ?", model.VisibilityPublic)
|
||||
Where("posts.visibility = ?", model.VisibilityPublic).
|
||||
Where("posts.scheduled_at IS NULL OR posts.scheduled_at <= NOW()")
|
||||
return r.pageResults(query, offset, limit)
|
||||
}
|
||||
|
||||
// FindScheduledDue 查询到期未发布的定时文章
|
||||
func (r *PostRepo) FindScheduledDue() ([]model.Post, error) {
|
||||
var posts []model.Post
|
||||
err := r.db.Where("status = ? AND scheduled_at IS NOT NULL AND scheduled_at <= NOW()", model.PostStatusApproved).
|
||||
Find(&posts).Error
|
||||
return posts, err
|
||||
}
|
||||
|
||||
// FindByUserIDAndStatus 分页查询某用户指定状态的帖子(空 status=全状态)
|
||||
func (r *PostRepo) FindByUserIDAndStatus(userID uint, status string, offset, limit int) ([]model.Post, int64, error) {
|
||||
query := r.buildQuery("", status).
|
||||
|
||||
Reference in New Issue
Block a user