Delete 删除帖子
(ctx context.Context, postId uint, uid int64)
| 239 | |
| 240 | // Delete 删除帖子 |
| 241 | func (p *postRepository) Delete(ctx context.Context, postId uint, uid int64) error { |
| 242 | // 获取帖子 |
| 243 | post, err := p.GetPostById(ctx, postId, uid) |
| 244 | if err != nil { |
| 245 | return fmt.Errorf("获取帖子失败: %w", err) |
| 246 | } |
| 247 | |
| 248 | if post.ID == 0 { |
| 249 | return fmt.Errorf("帖子不存在") |
| 250 | } |
| 251 | |
| 252 | // 删除帖子 |
| 253 | if err := p.dao.Delete(ctx, postId, uid); err != nil { |
| 254 | p.l.Error("删除帖子失败", zap.Error(err), zap.Uint("post_id", postId)) |
| 255 | return fmt.Errorf("删除帖子失败: %w", err) |
| 256 | } |
| 257 | |
| 258 | if post.Status == domain.Published { |
| 259 | p.refreshCache(job.RefreshTypeAll, "*", postId) |
| 260 | } |
| 261 | |
| 262 | p.refreshCache(job.RefreshTypeNormal, "*", postId) |
| 263 | |
| 264 | return nil |
| 265 | } |
| 266 | |
| 267 | // GetPost 获取帖子 |
| 268 | func (p *postRepository) GetPost(ctx context.Context, postId uint) (domain.Post, error) { |
nothing calls this directly
no test coverage detected