fix(social): 关注与取关改为幂等写入
SocialRepository.Follow 和 Unfollow 返回本次是否真的写入。判重交给唯一索引 idx_social_follower_vlogger。 因此重复关注和重复取关返回 200。重复请求不再落成 500。 缓存失效与通知只在真的变更时发生。自关注返回 400。响应体新增 created 与 deleted 字段。 SocialWorker 的调用只适配新签名,职责不变。删除它由后续提交完成。 验证:go build ./... 通过,go test -count=1 ./internal/social/... ./internal/worker/... 全绿。
This commit is contained in:
@@ -45,7 +45,7 @@ func (w *SocialWorker) process(ctx context.Context, d amqp.Delivery) error {
|
||||
|
||||
switch evt.Action {
|
||||
case "follow":
|
||||
err := w.repo.Follow(ctx, &social.Social{
|
||||
_, err := w.repo.Follow(ctx, &social.Social{
|
||||
FollowerID: evt.FollowerID,
|
||||
VloggerID: evt.VloggerID,
|
||||
})
|
||||
@@ -59,10 +59,11 @@ func (w *SocialWorker) process(ctx context.Context, d amqp.Delivery) error {
|
||||
}
|
||||
return err
|
||||
case "unfollow":
|
||||
return w.repo.Unfollow(ctx, &social.Social{
|
||||
_, err := w.repo.Unfollow(ctx, &social.Social{
|
||||
FollowerID: evt.FollowerID,
|
||||
VloggerID: evt.VloggerID,
|
||||
})
|
||||
return err
|
||||
default:
|
||||
return rabbitmq.Permanent(fmt.Errorf("social worker: unknown action %q", evt.Action))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user