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

Method GetPostById

internal/repository/post.go:117–133  ·  view source on GitHub ↗

GetPostById 获取帖子详细信息

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

Source from the content-addressed store, hash-verified

115
116// GetPostById 获取帖子详细信息
117func (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 获取已发布的帖子详细信息
136func (p *postRepository) GetPublishPostById(ctx context.Context, postId uint) (domain.Post, error) {

Callers 1

DeleteMethod · 0.95

Calls 3

ToDomainPostFunction · 0.92
GetMethod · 0.65
GetByIdMethod · 0.65

Tested by

no test coverage detected