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

Method UpdateStatus

internal/repository/post.go:88–114  ·  view source on GitHub ↗

UpdateStatus 更新帖子状态

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

Source from the content-addressed store, hash-verified

86
87// UpdateStatus 更新帖子状态
88func (p *postRepository) UpdateStatus(ctx context.Context, postId uint, uid int64, status uint8) error {
89 post, err := p.dao.GetById(ctx, postId, uid)
90 if err != nil {
91 p.l.Error("获取帖子失败", zap.Error(err), zap.Uint("post_id", postId))
92 return fmt.Errorf("获取帖子失败: %w", err)
93 }
94
95 // 更新帖子状态
96 if err := p.dao.UpdateStatus(ctx, postId, uid, status); err != nil {
97 p.l.Error("更新帖子状态失败",
98 zap.Error(err),
99 zap.Uint("post_id", postId),
100 zap.Int64("uid", uid),
101 zap.Uint8("status", status))
102 return fmt.Errorf("更新帖子状态失败: %w", err)
103 }
104
105 if status == domain.Published {
106 p.refreshCache(job.RefreshTypePub, "*")
107 } else if status != domain.Published && post.Status == domain.Published {
108 p.refreshCache(job.RefreshTypeAll, "*", postId)
109 } else {
110 p.refreshCache(job.RefreshTypeNormal, "*", postId)
111 }
112
113 return nil
114}
115
116// GetPostById 获取帖子详细信息
117func (p *postRepository) GetPostById(ctx context.Context, postId uint, uid int64) (domain.Post, error) {

Callers

nothing calls this directly

Calls 3

refreshCacheMethod · 0.95
GetByIdMethod · 0.65
UpdateStatusMethod · 0.65

Tested by

no test coverage detected