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 @@ -16,10 +16,15 @@ public class FindIntroduceResponse implements SearchResultResponse {
private Long introId;
private String title;
private String content;
private LocalDate createdDate;
private LocalDate updatedDate;

// @Override
// public LocalDate getCreatedDate() {
// return createdDate;
// }

@Override
public LocalDate getCreatedDate() {
return createdDate;
public LocalDate getUpdatedDate() {
return updatedDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ public class FindMasterIntroduceResponse implements SearchResultResponse {
private Long masterIntroId;
private String title;
private String content;
private LocalDate createdDate;
private LocalDate updatedDate;

// @Override
// public LocalDate getCreatedDate() {
// return createdDate;
// }

@Override
public LocalDate getCreatedDate() {
return createdDate;
public LocalDate getUpdatedDate() {
return updatedDate;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
import java.time.LocalDate;

public interface SearchResultResponse {
LocalDate getCreatedDate();
// LocalDate getCreatedDate();
LocalDate getUpdatedDate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public interface IntroduceRepository extends JpaRepository<Introduce, Long> {
Page<Introduce> findActiveIntroduces(@Param("memberId") Long memberId, @Param("state") int state, Pageable pageable);


@Query("SELECT i FROM Introduce i JOIN FETCH i.questions q WHERE i.memberId = :memberId AND q.content LIKE %:keyword%")
@Query("""
SELECT DISTINCT i
FROM Introduce i
JOIN FETCH i.questions q
WHERE i.memberId = :memberId
AND LOWER(CAST(q.content AS string)) LIKE CONCAT('%', LOWER(:keyword), '%')
""")
List<Introduce> searchIntroduceByKeywordForMember(@Param("keyword") String keyword, @Param("memberId") Long memberId);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
public interface MasterIntroduceRepository extends JpaRepository<MasterIntroduce, Long> {
Optional<MasterIntroduce> findByMemberId(Long memberId);

@Query("SELECT DISTINCT m FROM MasterIntroduce m JOIN FETCH m.masterQuestion q WHERE m.memberId = :memberId AND q.content LIKE %:keyword%")
@Query("""
SELECT DISTINCT m
FROM MasterIntroduce m
JOIN FETCH m.masterQuestion q
WHERE m.memberId = :memberId
AND LOWER(CAST(q.content AS string)) LIKE CONCAT('%', LOWER(:keyword), '%')
""")
List<MasterIntroduce> searchMasterIntroduceByKeywordForMember(@Param("keyword") String keyword, @Param("memberId") Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -269,48 +269,44 @@ public Long deleteIntro(Member requestMember, Long introId, Long recruitId) {

@Override
public Map<String, Object> searchIntroduceAndMasterByKeyword(String keyword, Member requestMember) {
// Introduce 검색
List<FindIntroduceResponse> introduceList = introduceRepository.searchIntroduceByKeywordForMember(keyword, requestMember.getId())
.stream()
.flatMap(introduce -> introduce.getQuestions().stream()
.filter(q -> q.getContent().contains(keyword)) // ✨ filter 먼저 적용
.map(q -> FindIntroduceResponse.builder()
.introId(introduce.getId())
.title(introduce.getRecruit().getTitle())
.content(q.getContent())
.createdDate(introduce.getCreatedAt().toLocalDate())
.build()))
.collect(Collectors.toList());

// MasterIntroduce 검색
List<FindMasterIntroduceResponse> masterIntroduceList = masterIntroduceRepository.searchMasterIntroduceByKeywordForMember(keyword, requestMember.getId())
.stream()
.flatMap(masterIntroduce -> masterIntroduce.getMasterQuestion().stream()
.filter(mq -> mq.getContent().contains(keyword)) // ✨ filter 먼저 적용
.map(mq -> FindMasterIntroduceResponse.builder()
.masterIntroId(masterIntroduce.getId())
.title("Master")
.content(mq.getContent())
.createdDate(masterIntroduce.getCreatedAt().toLocalDate())
.build()))
.collect(Collectors.toList());

// 공통 결과로 합치기 + 정렬 (최신순)
List<FindIntroduceResponse> introduceList =
introduceRepository.searchIntroduceByKeywordForMember(keyword, requestMember.getId())
.stream()
.flatMap(introduce -> introduce.getQuestions().stream()
.map(q -> FindIntroduceResponse.builder()
.introId(introduce.getId())
.title(introduce.getRecruit().getTitle())
.content(q.getContent())
.updatedDate(introduce.getUpdatedAt().toLocalDate())
.build()))
.collect(Collectors.toList());

List<FindMasterIntroduceResponse> masterIntroduceList =
masterIntroduceRepository.searchMasterIntroduceByKeywordForMember(keyword, requestMember.getId())
.stream()
.flatMap(masterIntroduce -> masterIntroduce.getMasterQuestion().stream()
.map(mq -> FindMasterIntroduceResponse.builder()
.masterIntroId(masterIntroduce.getId())
.title("Master")
.content(mq.getContent())
.updatedDate(masterIntroduce.getUpdatedAt().toLocalDate())
.build()))
.collect(Collectors.toList());

// 합치기 + 최신순 정렬
List<SearchResultResponse> result = new ArrayList<>();
result.addAll(masterIntroduceList);
result.addAll(introduceList);

result.sort(Comparator.comparing(SearchResultResponse::getCreatedDate).reversed()); // 최신순 정렬
result.sort(Comparator.comparing(SearchResultResponse::getUpdatedDate).reversed());

// 응답 반환
Map<String, Object> response = new LinkedHashMap<>();
response.put("count", result.size());
response.put("data", result);

return response;
}


@Override
@Transactional
public Introduce findByRecruitId(Long recruitId) {
Expand Down
Loading