Collect 处理收藏逻辑
(ctx context.Context, postId uint, uid int64)
| 62 | |
| 63 | // Collect 处理收藏逻辑 |
| 64 | func (i *interactiveService) Collect(ctx context.Context, postId uint, uid int64) error { |
| 65 | if postId == 0 || uid <= 0 { |
| 66 | return errors.New("invalid parameters") |
| 67 | } |
| 68 | |
| 69 | collected, err := i.repo.Collected(ctx, postId, uid) |
| 70 | if err != nil && !errors.Is(err, dao.ErrRecordNotFound) { |
| 71 | i.l.Error("收藏状态查询失败", zap.Error(err), zap.Uint("postId", postId), zap.Int64("uid", uid)) |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | if collected { |
| 76 | return errors.New("已收藏") |
| 77 | } |
| 78 | |
| 79 | return i.repo.IncrCollectionItem(ctx, postId, uid) |
| 80 | } |
| 81 | |
| 82 | // CancelCollect 处理取消收藏逻辑 |
| 83 | func (i *interactiveService) CancelCollect(ctx context.Context, postId uint, uid int64) error { |
nothing calls this directly
no test coverage detected