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 2222c4f8..28eda529 100644 --- a/src/main/java/team7/inplace/place/application/PlaceService.java +++ b/src/main/java/team7/inplace/place/application/PlaceService.java @@ -1,5 +1,11 @@ package team7.inplace.place.application; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -28,9 +34,6 @@ import team7.inplace.video.domain.Video; import team7.inplace.video.persistence.VideoRepository; -import java.util.*; -import java.util.stream.Collectors; - @Service @RequiredArgsConstructor public class PlaceService { @@ -44,21 +47,21 @@ public class PlaceService { private final LikedPlaceRepository likedPlaceRepository; public Page getPlacesWithinRadius( - PlacesCoordinateCommand placesCoordinateCommand, - PlacesFilterParamsCommand placesFilterParamsCommand) { + PlacesCoordinateCommand placesCoordinateCommand, + PlacesFilterParamsCommand placesFilterParamsCommand) { // categories와 influencers 필터 처리 List categoryFilters = placesFilterParamsCommand.isCategoryFilterExists() - ? Arrays.stream(placesFilterParamsCommand.categories().split(",")).toList() - : null; + ? Arrays.stream(placesFilterParamsCommand.categories().split(",")).toList() + : null; List influencerFilters = placesFilterParamsCommand.isInfluencerFilterExists() - ? Arrays.stream(placesFilterParamsCommand.influencers().split(",")).toList() - : null; + ? Arrays.stream(placesFilterParamsCommand.influencers().split(",")).toList() + : null; // 주어진 좌표로 장소를 찾고, 해당 페이지의 결과를 가져옵니다. Page placesPage = getPlacesByDistance(placesCoordinateCommand, categoryFilters, - influencerFilters); + influencerFilters); // Place ID 목록 추출 List placeIds = getPlaceIds(placesPage); @@ -66,7 +69,7 @@ public Page getPlacesWithinRadius( // influencer 조회 => video->Map(placeId, influencerName) List