Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,4 +26,20 @@ public interface FollowJpaRepository extends JpaRepository<Follow, Long> {

@Query("SELECT f.followingId FROM Follow f WHERE f.followerId = :followerId")
List<Long> 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);
}
Loading