Like 处理点赞逻辑
(ctx context.Context, postId uint, uid int64)
| 35 | |
| 36 | // Like 处理点赞逻辑 |
| 37 | func (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 处理取消点赞逻辑 |
| 56 | func (i *interactiveService) CancelLike(ctx context.Context, postId uint, uid int64) error { |