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

Method Like

internal/service/interactive.go:37–53  ·  view source on GitHub ↗

Like 处理点赞逻辑

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

Source from the content-addressed store, hash-verified

35
36// Like 处理点赞逻辑
37func (i *interactiveService) Like(ctx context.Context, postId uint, uid int64) error {
38 if postId == 0 || uid <= 0 {
39 return errors.New("invalid parameters")
40 }
41
42 exist, err := i.repo.Liked(ctx, postId, uid)
43 if err != nil && !errors.Is(err, dao.ErrRecordNotFound) {
44 i.l.Error("点赞状态查询失败", zap.Error(err), zap.Uint("postId", postId), zap.Int64("uid", uid))
45 return err
46 }
47
48 if exist {
49 return i.repo.DecrLike(ctx, postId, uid)
50 }
51
52 return i.repo.IncrLike(ctx, postId, uid)
53}
54
55// CancelLike 处理取消点赞逻辑
56func (i *interactiveService) CancelLike(ctx context.Context, postId uint, uid int64) error {

Callers

nothing calls this directly

Calls 3

LikedMethod · 0.65
DecrLikeMethod · 0.65
IncrLikeMethod · 0.65

Tested by

no test coverage detected