🐛 Fix user cannot get draft posts

This commit is contained in:
2025-03-08 21:38:41 +08:00
parent dd5ce8074b
commit 5f5f2bd1a5
2 changed files with 21 additions and 1 deletions

View File

@ -290,6 +290,20 @@ func FilterPostDraft(tx *gorm.DB) *gorm.DB {
return tx.Where("is_draft = ? OR is_draft IS NULL", false)
}
func FilterPostDraftWithAuthor(tx *gorm.DB, uid uint) *gorm.DB {
var publishers []models.Publisher
if err := database.C.Where("account_id = ?", uid).Find(&publishers).Error; err != nil {
return FilterPostDraft(tx)
}
if len(publishers) == 0 {
return FilterPostDraft(tx)
}
idSet := lo.Map(publishers, func(item models.Publisher, index int) uint {
return item.ID
})
return tx.Where("(is_draft = ? OR is_draft IS NULL) OR publisher_id IN ?", false, idSet)
}
func FilterPostWithFuzzySearch(tx *gorm.DB, probe string) *gorm.DB {
if len(probe) == 0 {
return tx