GetPost 获取帖子
(ctx context.Context, postId uint)
| 266 | |
| 267 | // GetPost 获取帖子 |
| 268 | func (p *postRepository) GetPost(ctx context.Context, postId uint) (domain.Post, error) { |
| 269 | dp, err := p.dao.GetPost(ctx, postId) |
| 270 | if err != nil { |
| 271 | p.l.Error("获取帖子失败", zap.Error(err), zap.Uint("post_id", postId)) |
| 272 | return domain.Post{}, fmt.Errorf("获取帖子失败: %w", err) |
| 273 | } |
| 274 | |
| 275 | if err := p.cache.Set(ctx, fmt.Sprint(postId), change.ToDomainPost(dp)); err != nil { |
| 276 | p.l.Error("设置帖子缓存失败", zap.Error(err), zap.Uint("post_id", postId)) |
| 277 | } |
| 278 | |
| 279 | return change.ToDomainPost(dp), nil |
| 280 | } |
| 281 | |
| 282 | // ListAllPosts 获取所有帖子 |
| 283 | func (p *postRepository) ListAllPosts(ctx context.Context, pagination domain.Pagination) ([]domain.Post, error) { |
nothing calls this directly
no test coverage detected