refactor(dto, repository): standardize pagination field names and update moderation status handling
- Changed JSON field names from "items" to "list" in various cursor pagination response DTOs for consistency. - Updated moderation status update methods in CommentRepository and PostRepository to use UpdateColumn for better clarity and to ensure that moderation actions do not affect content update timestamps.
This commit is contained in:
@@ -114,13 +114,14 @@ func (r *PostRepository) UpdateWithImages(post *model.Post, images *[]string) er
|
||||
|
||||
// UpdateModerationStatus 更新帖子审核状态
|
||||
func (r *PostRepository) UpdateModerationStatus(postID string, status model.PostStatus, rejectReason string, reviewedBy string) error {
|
||||
// 审核状态更新属于管理操作,不应影响帖子内容更新时间(updated_at)
|
||||
updates := map[string]interface{}{
|
||||
"status": status,
|
||||
"reviewed_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
"reviewed_by": reviewedBy,
|
||||
"reject_reason": rejectReason,
|
||||
}
|
||||
return r.db.Model(&model.Post{}).Where("id = ?", postID).Updates(updates).Error
|
||||
return r.db.Model(&model.Post{}).Where("id = ?", postID).UpdateColumns(updates).Error
|
||||
}
|
||||
|
||||
// Delete 删除帖子(软删除,同时清理关联数据)
|
||||
@@ -252,8 +253,9 @@ func (r *PostRepository) Like(postID, userID string) error {
|
||||
}
|
||||
|
||||
// 增加帖子点赞数并同步热度分
|
||||
// 点赞属于统计字段更新,不应影响帖子内容更新时间(updated_at)
|
||||
return tx.Model(&model.Post{}).Where("id = ?", postID).
|
||||
Updates(map[string]interface{}{
|
||||
UpdateColumns(map[string]any{
|
||||
"likes_count": gorm.Expr("likes_count + 1"),
|
||||
"hot_score": gorm.Expr("(likes_count + 1) * 2 + comments_count * 3 + views_count * 0.1"),
|
||||
}).Error
|
||||
@@ -269,8 +271,9 @@ func (r *PostRepository) Unlike(postID, userID string) error {
|
||||
}
|
||||
if result.RowsAffected > 0 {
|
||||
// 减少帖子点赞数并同步热度分
|
||||
// 取消点赞属于统计字段更新,不应影响帖子内容更新时间(updated_at)
|
||||
return tx.Model(&model.Post{}).Where("id = ?", postID).
|
||||
Updates(map[string]interface{}{
|
||||
UpdateColumns(map[string]any{
|
||||
"likes_count": gorm.Expr("likes_count - 1"),
|
||||
"hot_score": gorm.Expr("(likes_count - 1) * 2 + comments_count * 3 + views_count * 0.1"),
|
||||
}).Error
|
||||
@@ -701,14 +704,16 @@ func (r *PostRepository) BatchUpdateStatus(ids []string, status model.PostStatus
|
||||
|
||||
// UpdatePinStatus 更新帖子置顶状态
|
||||
func (r *PostRepository) UpdatePinStatus(postID string, isPinned bool) error {
|
||||
// 置顶状态属于管理操作,不应影响帖子内容更新时间(updated_at)
|
||||
return r.db.Model(&model.Post{}).Where("id = ?", postID).
|
||||
Update("is_pinned", isPinned).Error
|
||||
UpdateColumn("is_pinned", isPinned).Error
|
||||
}
|
||||
|
||||
// UpdateFeatureStatus 更新帖子加精状态
|
||||
func (r *PostRepository) UpdateFeatureStatus(postID string, isFeatured bool) error {
|
||||
// 加精状态属于管理操作,不应影响帖子内容更新时间(updated_at)
|
||||
return r.db.Model(&model.Post{}).Where("id = ?", postID).
|
||||
Update("is_featured", isFeatured).Error
|
||||
UpdateColumn("is_featured", isFeatured).Error
|
||||
}
|
||||
|
||||
// ========== Cursor Pagination Methods ==========
|
||||
|
||||
Reference in New Issue
Block a user