From 5ac6f64a28388e86ed2b2dddf1f91ceee677cec6 Mon Sep 17 00:00:00 2001 From: chaechaen Date: Thu, 22 Aug 2024 00:16:38 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=82=B4=EC=A3=BC=EB=B3=80=20=EB=8F=99?= =?UTF-8?q?=ED=96=89=EA=B8=80=20=EA=B5=AD=EA=B0=80=EB=A7=8C=20=EC=9D=BC?= =?UTF-8?q?=EC=B9=98=ED=95=B4=EB=8F=84=20=EC=A1=B0=ED=9A=8C=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../companyPost/application/CompanyPostService.java | 13 ++++++++++--- .../domain/repository/CompanyPostRepository.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java b/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java index 61069af9..f9dac257 100644 --- a/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java +++ b/src/main/java/com/on/server/domain/companyPost/application/CompanyPostService.java @@ -138,9 +138,16 @@ public List getRecentCompanyPosts() { // 내 주변 동행글 조회 public List getNearbyCompanyPostsByLikeTravelArea(Long companyPostId) { - CompanyPostResponseDTO post = getCompanyPostById(companyPostId).get(0); // 첫 번째 요소 선택 - String firstCountry = post.getTravelArea().get(0); // 첫 번째 국가를 기준으로 설정 - List nearbyPosts = companyPostRepository.findTop5ByTravelAreaLike(firstCountry, companyPostId); // 내 게시글 제외 + + // 여러 개의 travel area 중에서 첫 번째만 선택 + CompanyPostResponseDTO post = getCompanyPostById(companyPostId).get(0); + + // 국가만 일치해도 조회되도록 국가 부분만 추출 + String firstCountry = post.getTravelArea().get(0).split(" ")[0]; + + // 국가와 일치하는 다른 게시글을 조회, 현재 게시글은 제외 + List nearbyPosts = companyPostRepository.findTop5ByTravelAreaLike(firstCountry, companyPostId); + return nearbyPosts.stream() .map(this::mapToCompanyPostResponseDTO) .collect(Collectors.toList()); diff --git a/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java b/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java index 4867b4c6..fa46da7a 100644 --- a/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java +++ b/src/main/java/com/on/server/domain/companyPost/domain/repository/CompanyPostRepository.java @@ -41,7 +41,7 @@ default List findTop4ByOrderByCreatedAtDesc() { @Query("SELECT c FROM CompanyPost c JOIN c.travelArea t WHERE t LIKE CONCAT('%', :country, '%') AND c.isRecruitCompleted = false ORDER BY c.createdAt DESC") List findTop5ByTravelArea(@Param("country") String country, Pageable pageable); - @Query("SELECT c FROM CompanyPost c WHERE :country MEMBER OF c.travelArea AND c.isRecruitCompleted = false AND c.id <> :companyPostId ORDER BY c.createdAt DESC") + @Query("SELECT c FROM CompanyPost c JOIN c.travelArea t WHERE t LIKE CONCAT('%', :country, '%') AND c.isRecruitCompleted = false AND c.id <> :companyPostId ORDER BY c.createdAt DESC") List findTop5ByTravelAreaLike(@Param("country") String country, @Param("companyPostId") Long companyPostId); // 최신순 정렬