diff --git a/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java b/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java index a73279c8..8e945b75 100644 --- a/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java +++ b/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; @Tag(name = "introduce", description = "자기소개서 API") @RestController @@ -96,9 +97,12 @@ public ResponseEntity delete( @GetMapping("/search") @Operation(summary = "키워드로 자기소개서 문단 검색") - public ResponseEntity> searchIntroduceByKeyword(@RequestParam String keyword) { - List response = introduceService.searchIntroduceAndMasterByKeyword(keyword); + public ResponseEntity> searchIntroduceByKeyword(@Login LoginInfo loginInfo, @RequestParam String keyword) { + Member requestMember = memberService.getById(loginInfo.getMemberId()); + Map response = introduceService.searchIntroduceAndMasterByKeyword(keyword, requestMember); return ResponseEntity.status(HttpStatus.OK).body(response); } + + } diff --git a/src/main/java/umc/kkijuk/server/introduce/controller/response/FindIntroduceResponse.java b/src/main/java/umc/kkijuk/server/introduce/controller/response/FindIntroduceResponse.java index 9947a492..366977c3 100644 --- a/src/main/java/umc/kkijuk/server/introduce/controller/response/FindIntroduceResponse.java +++ b/src/main/java/umc/kkijuk/server/introduce/controller/response/FindIntroduceResponse.java @@ -13,5 +13,5 @@ public class FindIntroduceResponse { private Long introId; private String title; private String content; - private LocalDateTime createdDate; + private LocalDate createdDate; } diff --git a/src/main/java/umc/kkijuk/server/introduce/controller/response/FindMasterIntroduceResponse.java b/src/main/java/umc/kkijuk/server/introduce/controller/response/FindMasterIntroduceResponse.java index 291429d0..437b32dd 100644 --- a/src/main/java/umc/kkijuk/server/introduce/controller/response/FindMasterIntroduceResponse.java +++ b/src/main/java/umc/kkijuk/server/introduce/controller/response/FindMasterIntroduceResponse.java @@ -13,5 +13,5 @@ public class FindMasterIntroduceResponse { private Long masterIntroId; private String title; private String content; - private LocalDateTime createdDate; + private LocalDate createdDate; } diff --git a/src/main/java/umc/kkijuk/server/introduce/repository/IntroduceRepository.java b/src/main/java/umc/kkijuk/server/introduce/repository/IntroduceRepository.java index feb9f30d..e7ff9a75 100644 --- a/src/main/java/umc/kkijuk/server/introduce/repository/IntroduceRepository.java +++ b/src/main/java/umc/kkijuk/server/introduce/repository/IntroduceRepository.java @@ -20,8 +20,8 @@ public interface IntroduceRepository extends JpaRepository { @Query("SELECT i FROM Introduce i " + "JOIN i.questions q " + - "WHERE q.content LIKE %:keyword%") - List searchIntroduceByKeyword(String keyword); + "WHERE i.memberId = :memberId AND q.content LIKE %:keyword%") + List searchIntroduceByKeywordForMember(String keyword, Long memberId); } diff --git a/src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java b/src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java index 8141d5d3..31eff56a 100644 --- a/src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java +++ b/src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java @@ -12,6 +12,7 @@ public interface MasterIntroduceRepository extends JpaRepository findByMemberId(Long memberId); @Query("SELECT m FROM MasterIntroduce m " + "JOIN m.masterQuestion mq " + - "WHERE mq.content LIKE %:keyword%") - List searchMasterIntroduceByKeyword(String keyword); + "WHERE m.memberId = :memberId AND mq.content LIKE %:keyword%") + List searchMasterIntroduceByKeywordForMember(String keyword, Long memberId); + } diff --git a/src/main/java/umc/kkijuk/server/introduce/service/IntroduceService.java b/src/main/java/umc/kkijuk/server/introduce/service/IntroduceService.java index 5dca722a..809f1e98 100644 --- a/src/main/java/umc/kkijuk/server/introduce/service/IntroduceService.java +++ b/src/main/java/umc/kkijuk/server/introduce/service/IntroduceService.java @@ -174,9 +174,9 @@ public List getIntroduceTitles() { .collect(Collectors.toList()); // Collect titles into a List }*/ - public List searchIntroduceAndMasterByKeyword(String keyword) { + public Map searchIntroduceAndMasterByKeyword(String keyword, Member requestMember) { // 자기소개서 검색 - List introduceList = introduceRepository.searchIntroduceByKeyword(keyword) + List introduceList = introduceRepository.searchIntroduceByKeywordForMember(keyword, requestMember.getId()) .stream() .flatMap(introduce -> introduce.getQuestions().stream() .filter(q -> q.getContent().contains(keyword)) @@ -184,12 +184,12 @@ public List searchIntroduceAndMasterByKeyword(String keyword) { .introId(introduce.getId()) .title(introduce.getRecruit().getTitle()) .content(q.getContent()) - .createdDate(introduce.getCreatedAt()) + .createdDate(introduce.getCreatedAt().toLocalDate()) .build())) .collect(Collectors.toList()); // 마스터 자기소개서 검색 - List masterIntroduceList = masterIntroduceRepository.searchMasterIntroduceByKeyword(keyword) + List masterIntroduceList = masterIntroduceRepository.searchMasterIntroduceByKeywordForMember(keyword, requestMember.getId()) .stream() .flatMap(masterIntroduce -> masterIntroduce.getMasterQuestion().stream() .filter(mq -> mq.getContent().contains(keyword)) @@ -197,16 +197,24 @@ public List searchIntroduceAndMasterByKeyword(String keyword) { .masterIntroId(masterIntroduce.getId()) .title("Master") .content(mq.getContent()) - .createdDate(masterIntroduce.getCreatedAt()) + .createdDate(masterIntroduce.getCreatedAt().toLocalDate()) .build())) .collect(Collectors.toList()); List result = new ArrayList<>(); - result.addAll(introduceList); result.addAll(masterIntroduceList); + result.addAll(introduceList); + + int count = result.size(); - return result; + Map response = new LinkedHashMap<>(); + response.put("count", count); + response.put("data", result); + + return response; } + + }