Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 내주변 동행글 국가만 일치해도 조회되도록 수정 #73

Merged
merged 1 commit into from
Aug 21, 2024
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 @@ -138,9 +138,16 @@ public List<CompanyPostResponseDTO> getRecentCompanyPosts() {

// 내 주변 동행글 조회
public List<CompanyPostResponseDTO> getNearbyCompanyPostsByLikeTravelArea(Long companyPostId) {
CompanyPostResponseDTO post = getCompanyPostById(companyPostId).get(0); // 첫 번째 요소 선택
String firstCountry = post.getTravelArea().get(0); // 첫 번째 국가를 기준으로 설정
List<CompanyPost> nearbyPosts = companyPostRepository.findTop5ByTravelAreaLike(firstCountry, companyPostId); // 내 게시글 제외

// 여러 개의 travel area 중에서 첫 번째만 선택
CompanyPostResponseDTO post = getCompanyPostById(companyPostId).get(0);

// 국가만 일치해도 조회되도록 국가 부분만 추출
String firstCountry = post.getTravelArea().get(0).split(" ")[0];

// 국가와 일치하는 다른 게시글을 조회, 현재 게시글은 제외
List<CompanyPost> nearbyPosts = companyPostRepository.findTop5ByTravelAreaLike(firstCountry, companyPostId);

return nearbyPosts.stream()
.map(this::mapToCompanyPostResponseDTO)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ default List<CompanyPost> 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<CompanyPost> 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<CompanyPost> findTop5ByTravelAreaLike(@Param("country") String country, @Param("companyPostId") Long companyPostId);

// 최신순 정렬
Expand Down
Loading