MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / GetPostById

Method GetPostById

internal/service/post.go:107–131  ·  view source on GitHub ↗

GetPostById 获取帖子详细信息

(ctx context.Context, postId uint, uid int64)

Source from the content-addressed store, hash-verified

105
106// GetPostById 获取帖子详细信息
107func (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 获取已发布的帖子详细信息
134func (p *postService) GetPublishPostById(ctx context.Context, postId uint, uid int64) (domain.Post, error) {

Callers

nothing calls this directly

Calls 2

GetPostByIdMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected