GetPostById 获取帖子详细信息
(ctx context.Context, postId uint, uid int64)
| 105 | |
| 106 | // GetPostById 获取帖子详细信息 |
| 107 | func (p *postService) GetPostById(ctx context.Context, postId uint, uid int64) (domain.Post, error) { |
| 108 | data, err := p.repo.GetPostById(ctx, postId, uid) |
| 109 | if err != nil { |
| 110 | p.l.Error("获取帖子失败", zap.Error(err)) |
| 111 | return domain.Post{}, fmt.Errorf("获取帖子失败: %w", err) |
| 112 | } |
| 113 | |
| 114 | inc, err := p.incRepo.Get(ctx, postId) |
| 115 | if err != nil && err != gorm.ErrRecordNotFound { |
| 116 | p.l.Error("获取互动数据失败", zap.Error(err)) |
| 117 | return domain.Post{}, fmt.Errorf("获取互动数据失败: %w", err) |
| 118 | } else if err == gorm.ErrRecordNotFound { |
| 119 | inc = domain.Interactive{ |
| 120 | LikeCount: 0, |
| 121 | ReadCount: 0, |
| 122 | CollectCount: 0, |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | data.LikeCount = inc.LikeCount |
| 127 | data.ReadCount = inc.ReadCount |
| 128 | data.CollectCount = inc.CollectCount |
| 129 | |
| 130 | return data, nil |
| 131 | } |
| 132 | |
| 133 | // GetPublishPostById 获取已发布的帖子详细信息 |
| 134 | func (p *postService) GetPublishPostById(ctx context.Context, postId uint, uid int64) (domain.Post, error) { |
nothing calls this directly
no test coverage detected