diff --git a/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java b/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java index a310f7e5..0ae36e7f 100644 --- a/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java +++ b/src/main/java/team7/inplace/likedPlace/persistence/LikedPlaceRepository.java @@ -9,14 +9,15 @@ import org.springframework.data.repository.query.Param; import team7.inplace.likedPlace.domain.LikedPlace; -import java.util.Optional; - public interface LikedPlaceRepository extends JpaRepository { Optional findByUserIdAndPlaceId(Long userId, Long placeId); - Page findByUserIdAndIsLikedTrue(Long userId, Pageable pageable); - @Query("SELECT l.place.id FROM LikedPlace l WHERE l.user.id = :userId AND l.isLiked = true") Set findPlaceIdsByUserIdAndIsLikedTrue(@Param("userId") Long userId); + + @Query("SELECT lp FROM LikedPlace lp JOIN FETCH lp.place WHERE lp.user.id = :userId AND lp.isLiked = true") + Page findByUserIdAndIsLikedTrueWithPlace(@Param("userId") Long userId, + Pageable pageable); + } diff --git a/src/main/java/team7/inplace/place/application/PlaceService.java b/src/main/java/team7/inplace/place/application/PlaceService.java index 022a1554..c8b061ab 100644 --- a/src/main/java/team7/inplace/place/application/PlaceService.java +++ b/src/main/java/team7/inplace/place/application/PlaceService.java @@ -225,10 +225,10 @@ public PlaceMessageCommand getPlaceMessageCommand(Long placeId) { } public Page getLikedPlaceInfo(Long userId, Pageable pageable) { - Page placePage = likedPlaceRepository.findByUserIdAndIsLikedTrue(userId, - pageable); + Page placePage = likedPlaceRepository.findByUserIdAndIsLikedTrueWithPlace( + userId, pageable); List placeIds = placePage.map(likedPlace -> likedPlace.getPlace().getId()).toList(); - List