Skip to content

Commit

Permalink
Feat : 자소서 검색 response값 count 추가 및 날짜 형태 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhun0331 committed Dec 3, 2024
1 parent fbfa3a5 commit fb4bc8e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Tag(name = "introduce", description = "자기소개서 API")
@RestController
Expand Down Expand Up @@ -96,9 +97,12 @@ public ResponseEntity<Object> delete(

@GetMapping("/search")
@Operation(summary = "키워드로 자기소개서 문단 검색")
public ResponseEntity<List<Object>> searchIntroduceByKeyword(@RequestParam String keyword) {
List<Object> response = introduceService.searchIntroduceAndMasterByKeyword(keyword);
public ResponseEntity<Map<String, Object>> searchIntroduceByKeyword(@Login LoginInfo loginInfo, @RequestParam String keyword) {
Member requestMember = memberService.getById(loginInfo.getMemberId());
Map<String, Object> response = introduceService.searchIntroduceAndMasterByKeyword(keyword, requestMember);
return ResponseEntity.status(HttpStatus.OK).body(response);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public class FindIntroduceResponse {
private Long introId;
private String title;
private String content;
private LocalDateTime createdDate;
private LocalDate createdDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public class FindMasterIntroduceResponse {
private Long masterIntroId;
private String title;
private String content;
private LocalDateTime createdDate;
private LocalDate createdDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public interface IntroduceRepository extends JpaRepository<Introduce, Long> {

@Query("SELECT i FROM Introduce i " +
"JOIN i.questions q " +
"WHERE q.content LIKE %:keyword%")
List<Introduce> searchIntroduceByKeyword(String keyword);
"WHERE i.memberId = :memberId AND q.content LIKE %:keyword%")
List<Introduce> searchIntroduceByKeywordForMember(String keyword, Long memberId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface MasterIntroduceRepository extends JpaRepository<MasterIntroduce
Optional<MasterIntroduce> findByMemberId(Long memberId);
@Query("SELECT m FROM MasterIntroduce m " +
"JOIN m.masterQuestion mq " +
"WHERE mq.content LIKE %:keyword%")
List<MasterIntroduce> searchMasterIntroduceByKeyword(String keyword);
"WHERE m.memberId = :memberId AND mq.content LIKE %:keyword%")
List<MasterIntroduce> searchMasterIntroduceByKeywordForMember(String keyword, Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -174,39 +174,47 @@ public List<String> getIntroduceTitles() {
.collect(Collectors.toList()); // Collect titles into a List
}*/

public List<Object> searchIntroduceAndMasterByKeyword(String keyword) {
public Map<String, Object> searchIntroduceAndMasterByKeyword(String keyword, Member requestMember) {
// 자기소개서 검색
List<FindIntroduceResponse> introduceList = introduceRepository.searchIntroduceByKeyword(keyword)
List<FindIntroduceResponse> introduceList = introduceRepository.searchIntroduceByKeywordForMember(keyword, requestMember.getId())
.stream()
.flatMap(introduce -> introduce.getQuestions().stream()
.filter(q -> q.getContent().contains(keyword))
.map(q -> FindIntroduceResponse.builder()
.introId(introduce.getId())
.title(introduce.getRecruit().getTitle())
.content(q.getContent())
.createdDate(introduce.getCreatedAt())
.createdDate(introduce.getCreatedAt().toLocalDate())
.build()))
.collect(Collectors.toList());

// 마스터 자기소개서 검색
List<FindMasterIntroduceResponse> masterIntroduceList = masterIntroduceRepository.searchMasterIntroduceByKeyword(keyword)
List<FindMasterIntroduceResponse> masterIntroduceList = masterIntroduceRepository.searchMasterIntroduceByKeywordForMember(keyword, requestMember.getId())
.stream()
.flatMap(masterIntroduce -> masterIntroduce.getMasterQuestion().stream()
.filter(mq -> mq.getContent().contains(keyword))
.map(mq -> FindMasterIntroduceResponse.builder()
.masterIntroId(masterIntroduce.getId())
.title("Master")
.content(mq.getContent())
.createdDate(masterIntroduce.getCreatedAt())
.createdDate(masterIntroduce.getCreatedAt().toLocalDate())
.build()))
.collect(Collectors.toList());

List<Object> result = new ArrayList<>();
result.addAll(introduceList);
result.addAll(masterIntroduceList);
result.addAll(introduceList);

int count = result.size();

return result;
Map<String, Object> response = new LinkedHashMap<>();
response.put("count", count);
response.put("data", result);

return response;
}




}

0 comments on commit fb4bc8e

Please sign in to comment.