Skip to content

Commit

Permalink
[#112] 리팩토링
Browse files Browse the repository at this point in the history
- 팔로우 알림 중복 불가 처리
  • Loading branch information
JAEHEE25 committed Dec 16, 2024
1 parent 9af0600 commit 2753aa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import io.driver.codrive.modules.user.domain.User;
Expand All @@ -13,4 +15,14 @@ public interface FollowRepository extends JpaRepository<Follow, Long>, FollowRep
Optional<Follow> findByFollowingAndFollower(User following, User follower);

boolean existsByFollowingAndFollower(User following, User follower);

@Query(value = """
SELECT COUNT(*)
FROM follow f
WHERE f.following_id = :targetId
AND f.follower_id = :currentUserId
AND f.canceled = true
""",
nativeQuery = true)
Long getCanceledFollowCount(@Param("targetId") Long targetId, @Param("currentUserId") Long currentUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ public void follow(String nickname) {
throw new InternalServerErrorApplicationException("팔로우할 수 없습니다.");
}

notificationService.sendNotification(target, currentUser.getUserId(), NotificationType.FOLLOW,
currentUser.getNickname());
if (followRepository.getCanceledFollowCount(target.getUserId(), currentUser.getUserId()) == 0) {
notificationService.sendNotification(target, currentUser.getUserId(), NotificationType.FOLLOW,
currentUser.getNickname());
}

}

@Transactional
Expand Down

0 comments on commit 2753aa2

Please sign in to comment.