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

Method Delete

internal/repository/post.go:241–265  ·  view source on GitHub ↗

Delete 删除帖子

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

Source from the content-addressed store, hash-verified

239
240// Delete 删除帖子
241func (p *postRepository) Delete(ctx context.Context, postId uint, uid int64) error {
242 // 获取帖子
243 post, err := p.GetPostById(ctx, postId, uid)
244 if err != nil {
245 return fmt.Errorf("获取帖子失败: %w", err)
246 }
247
248 if post.ID == 0 {
249 return fmt.Errorf("帖子不存在")
250 }
251
252 // 删除帖子
253 if err := p.dao.Delete(ctx, postId, uid); err != nil {
254 p.l.Error("删除帖子失败", zap.Error(err), zap.Uint("post_id", postId))
255 return fmt.Errorf("删除帖子失败: %w", err)
256 }
257
258 if post.Status == domain.Published {
259 p.refreshCache(job.RefreshTypeAll, "*", postId)
260 }
261
262 p.refreshCache(job.RefreshTypeNormal, "*", postId)
263
264 return nil
265}
266
267// GetPost 获取帖子
268func (p *postRepository) GetPost(ctx context.Context, postId uint) (domain.Post, error) {

Callers

nothing calls this directly

Calls 3

GetPostByIdMethod · 0.95
refreshCacheMethod · 0.95
DeleteMethod · 0.65

Tested by

no test coverage detected