GetPostById 获取帖子详细信息
(ctx context.Context, postId uint, uid int64)
| 115 | |
| 116 | // GetPostById 获取帖子详细信息 |
| 117 | func (p *postRepository) GetPostById(ctx context.Context, postId uint, uid int64) (domain.Post, error) { |
| 118 | // 先从缓存中获取 |
| 119 | post, err := p.cache.Get(ctx, fmt.Sprint(postId)) |
| 120 | if err == nil { |
| 121 | return post, nil |
| 122 | } |
| 123 | |
| 124 | dp, err := p.dao.GetById(ctx, postId, uid) |
| 125 | if err != nil { |
| 126 | p.l.Error("获取帖子失败", zap.Error(err), zap.Uint("post_id", postId)) |
| 127 | return domain.Post{}, fmt.Errorf("获取帖子失败: %w", err) |
| 128 | } |
| 129 | |
| 130 | result := change.ToDomainPost(dp) |
| 131 | |
| 132 | return result, nil |
| 133 | } |
| 134 | |
| 135 | // GetPublishPostById 获取已发布的帖子详细信息 |
| 136 | func (p *postRepository) GetPublishPostById(ctx context.Context, postId uint) (domain.Post, error) { |
no test coverage detected