feat: 为Follow和UnFollow加上MQ

This commit is contained in:
Leon
2025-12-29 04:13:53 +08:00
parent 4225b026d7
commit 7200b55ca2
2 changed files with 19 additions and 4 deletions

View File

@@ -4,15 +4,17 @@ import (
"context"
"errors"
"feedsystem_video_go/internal/account"
"feedsystem_video_go/internal/middleware/rabbitmq"
)
type SocialService struct {
repo *SocialRepository
accountrepo *account.AccountRepository
socialMQ *rabbitmq.SocialMQ
}
func NewSocialService(repo *SocialRepository, accountrepo *account.AccountRepository) *SocialService {
return &SocialService{repo: repo, accountrepo: accountrepo}
func NewSocialService(repo *SocialRepository, accountrepo *account.AccountRepository, socialMQ *rabbitmq.SocialMQ) *SocialService {
return &SocialService{repo: repo, accountrepo: accountrepo, socialMQ: socialMQ}
}
func (s *SocialService) Follow(ctx context.Context, social *Social) error {
@@ -34,6 +36,9 @@ func (s *SocialService) Follow(ctx context.Context, social *Social) error {
if isFollowed {
return errors.New("already followed")
}
if s.socialMQ != nil {
s.socialMQ.Follow(ctx, social.FollowerID, social.VloggerID)
}
return s.repo.Follow(ctx, social)
}
@@ -53,6 +58,9 @@ func (s *SocialService) Unfollow(ctx context.Context, social *Social) error {
if !isFollowed {
return errors.New("not followed")
}
if s.socialMQ != nil {
s.socialMQ.UnFollow(ctx, social.FollowerID, social.VloggerID)
}
return s.repo.Unfollow(ctx, social)
}