diff --git a/prothsync/src/main/java/com/prothsync/prothsync/repository/jpa/FollowJpaRepository.java b/prothsync/src/main/java/com/prothsync/prothsync/repository/jpa/FollowJpaRepository.java index 4f92fbb..6d5444f 100644 --- a/prothsync/src/main/java/com/prothsync/prothsync/repository/jpa/FollowJpaRepository.java +++ b/prothsync/src/main/java/com/prothsync/prothsync/repository/jpa/FollowJpaRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -25,4 +26,20 @@ public interface FollowJpaRepository extends JpaRepository { @Query("SELECT f.followingId FROM Follow f WHERE f.followerId = :followerId") List findFollowingIdsByFollowerId(@Param("followerId") Long followerId); + + @Modifying + @Query("UPDATE User u SET u.followerCount = u.followerCount + 1 WHERE u.userId = :userId") + void incrementFollowerCount(@Param("userId") Long userId); + + @Modifying + @Query("UPDATE User u SET u.followerCount = u.followerCount - 1 WHERE u.userId = :userId AND u.followerCount > 0") + void decrementFollowerCount(@Param("userId") Long userId); + + @Modifying + @Query("UPDATE User u SET u.followingCount = u.followingCount + 1 WHERE u.userId = :userId") + void incrementFollowingCount(@Param("userId") Long userId); + + @Modifying + @Query("UPDATE User u SET u.followingCount = u.followingCount - 1 WHERE u.userId = :userId AND u.followingCount > 0") + void decrementFollowingCount(@Param("userId") Long userId); } \ No newline at end of file