Skip to content
Merged
Show file tree
Hide file tree
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 @@ -13,10 +13,8 @@ public interface PlaceRepository extends JpaRepository<Place, Long> {

List<Place> findByNameKoContainingIgnoreCaseOrNameEnContainingIgnoreCase(String nameKo, String nameEn);

@Query(value = "SELECT * FROM places WHERE JSON_CONTAINS(themes, :themeJson) LIMIT :limit", nativeQuery = true)
List<Place> findByThemeKeywordWithLimit(@Param("themeJson") String themeJson, @Param("limit") int limit);

Optional<Place> findByNameKo(String nameKo);
@Query(value = "SELECT * FROM places WHERE JSON_CONTAINS(themes, JSON_QUOTE(:keyword), '$') LIMIT :limit", nativeQuery = true)
List<Place> findByThemeKeywordWithLimit(@Param("keyword") String keyword, @Param("limit") int limit);

// JPQL의 MOD 함수로 홀수 placeId만 필터링
@Query("SELECT p FROM Place p WHERE MOD(p.placeId, 2) = 1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ public List<PlaceResponseDto> getPopularPlaces(Integer limit) {
}

public List<PlaceThemeResponseDto> getPlacesByTheme(String keyword, int limit) {
String jsonKeyword = "[\"" + keyword.toLowerCase() + "\"]";
List<Place> places = placeRepository.findByThemeKeywordWithLimit(jsonKeyword, limit);
// DB 저장 형식에 맞추어 정규화 (예: 전부 대문자 + 언더스코어)
String norm = keyword.toUpperCase(); // "K_POP", "K_DRAMA" 등

if (places.isEmpty()) {
throw new PlaceException(ErrorStatus.PLACE_NOT_FOUND);
}
List<Place> places = placeRepository.findByThemeKeywordWithLimit(norm, limit);
if (places.isEmpty()) throw new PlaceException(ErrorStatus.PLACE_NOT_FOUND);

return places.stream()
.map(PlaceThemeResponseDto::new)
.collect(Collectors.toList());
return places.stream().map(PlaceThemeResponseDto::new).collect(Collectors.toList());
}
}