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); // 최신순 정렬