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 @@ -63,11 +63,11 @@ public CommonResponse<StartRouteResponse> startRoute(
description = "추천 루트들을 조회한 결과를 반환합니다."
)@GetMapping("/recommend")
public CommonResponse<RouteRecommendListResponseDto> getRecommendedRoutes(
@RequestParam(required = false) List<Theme> themes,
@RequestParam(required = false) Theme theme,
@RequestParam(defaultValue = "20") int limit,
@RequestParam(defaultValue = "0") int offset) {

RouteRecommendListResponseDto response = routeService.getRecommendedRoutes(themes, limit, offset);
RouteRecommendListResponseDto response = routeService.getRecommendedRoutes(theme, limit, offset);
return CommonResponse.onSuccess(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
import java.util.List;

public interface RouteRepository extends JpaRepository<Route, Long> {

// 특정 테마를 포함하는 루트 조회
@Query(value = "SELECT * FROM routes r WHERE JSON_CONTAINS(r.themes, JSON_QUOTE(:theme))", nativeQuery = true)
List<Route> findByThemesContaining(@Param("theme") String theme);
// 지역별 루트 조회

// 지역별 루트 조회
@Query("SELECT r FROM Route r WHERE r.region.nameKo = :regionName")
List<Route> findByRegionName(@Param("regionName") String regionName);

// 테마와 지역으로 필터링된 루트 조회
@Query(value = "SELECT r.* FROM routes r LEFT JOIN regions reg ON r.region_id = reg.region_id WHERE (:themes IS NULL OR JSON_OVERLAPS(r.themes, CAST(:themes AS JSON))) AND (:regionName IS NULL OR reg.name_ko = :regionName)", nativeQuery = true)
List<Route> findByThemesAndRegion(@Param("themes") String themes, @Param("regionName") String regionName);

// 여러 테마 중 하나라도 포함하는 루트 조회
@Query(value = "SELECT * FROM routes r WHERE JSON_OVERLAPS(r.themes, CAST(:themes AS JSON))", nativeQuery = true)
List<Route> findByThemesContainingAny(@Param("themes") String themes);

// 인기도순 정렬 (비용 기준으로 대체)
@Query("SELECT r FROM Route r ORDER BY r.totalCost ASC")
List<Route> findAllOrderByPopularity();
Expand All @@ -34,12 +34,14 @@ public interface RouteRepository extends JpaRepository<Route, Long> {
// POPULAR 전체
List<Route> findByRouteType(RouteType routeType);

// POPULAR + themes 조건
// POPULAR + theme 조건

@Query(value = """
SELECT *
FROM routes r
WHERE r.route_type = 'POPULAR'
AND JSON_OVERLAPS(r.themes, CAST(:themesJson AS JSON))
""", nativeQuery = true)
List<Route> findPopularByThemes(@Param("themesJson") String themesJson);
}
SELECT * FROM routes
WHERE route_type = 'POPULAR'
AND JSON_CONTAINS(themes, :themeJson)
ORDER BY id ASC
""", nativeQuery = true)
List<Route> findPopularByThemes(@Param("themeJson") String themeJson);

}
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,12 @@ private Totals computeTotals(List<Place> selected, List<Long> orderedPlaceIds) {
private record Totals(int totalDurationSec, int totalDistanceMeters, int totalFare) {
}

public RouteRecommendListResponseDto getRecommendedRoutes(List<Theme> themes, int limit, int offset) {
public RouteRecommendListResponseDto getRecommendedRoutes(Theme theme, int limit, int offset) {
List<Route> allRoutes;

if (themes != null && !themes.isEmpty()) {
// themes를 JSON 배열 문자열로 변환
String themesJson = themes.stream()
.map(t -> "\"" + t.name() + "\"") // "FOOD", "CAFE" 이런 식으로
.collect(Collectors.joining(",", "[", "]"));

if (theme != null) {
// theme을 JSON 배열 문자열로 변환 (단일)
String themesJson = "[\"" + theme.name() + "\"]";
allRoutes = routeRepository.findPopularByThemes(themesJson);
} else {
allRoutes = routeRepository.findByRouteType(RouteType.POPULAR);
Expand Down Expand Up @@ -409,4 +406,4 @@ public RouteCreateResponseDto createRoute(RouteCreateRequestDto request) {
.regionName(savedRoute.getRegion() != null ? savedRoute.getRegion().getNameKo() : null)
.build();
}
}
}