UpdateStatus 更新帖子状态
(ctx context.Context, postId uint, uid int64, status uint8)
| 86 | |
| 87 | // UpdateStatus 更新帖子状态 |
| 88 | func (p *postRepository) UpdateStatus(ctx context.Context, postId uint, uid int64, status uint8) error { |
| 89 | post, err := p.dao.GetById(ctx, postId, uid) |
| 90 | if err != nil { |
| 91 | p.l.Error("获取帖子失败", zap.Error(err), zap.Uint("post_id", postId)) |
| 92 | return fmt.Errorf("获取帖子失败: %w", err) |
| 93 | } |
| 94 | |
| 95 | // 更新帖子状态 |
| 96 | if err := p.dao.UpdateStatus(ctx, postId, uid, status); err != nil { |
| 97 | p.l.Error("更新帖子状态失败", |
| 98 | zap.Error(err), |
| 99 | zap.Uint("post_id", postId), |
| 100 | zap.Int64("uid", uid), |
| 101 | zap.Uint8("status", status)) |
| 102 | return fmt.Errorf("更新帖子状态失败: %w", err) |
| 103 | } |
| 104 | |
| 105 | if status == domain.Published { |
| 106 | p.refreshCache(job.RefreshTypePub, "*") |
| 107 | } else if status != domain.Published && post.Status == domain.Published { |
| 108 | p.refreshCache(job.RefreshTypeAll, "*", postId) |
| 109 | } else { |
| 110 | p.refreshCache(job.RefreshTypeNormal, "*", postId) |
| 111 | } |
| 112 | |
| 113 | return nil |
| 114 | } |
| 115 | |
| 116 | // GetPostById 获取帖子详细信息 |
| 117 | func (p *postRepository) GetPostById(ctx context.Context, postId uint, uid int64) (domain.Post, error) { |
nothing calls this directly
no test coverage detected