From c3dd176b63fe0c09dceee1dfc8f1d9b5f92c684f Mon Sep 17 00:00:00 2001 From: Suhun0331 Date: Mon, 2 Dec 2024 21:02:51 +0900 Subject: [PATCH] =?UTF-8?q?Feat=20:=20=EC=9E=90=EC=86=8C=EC=84=9C=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=EA=B8=B0=EB=8A=A5(=EC=B4=88=EC=95=88)=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DashBoardServiceImpl.java | 2 +- .../controller/IntroduceController.java | 11 +++++ .../response/FindIntroduceResponse.java | 17 +++++++ .../response/FindMasterIntroduceResponse.java | 17 +++++++ .../domain/MasterIntroduceRepository.java | 11 ----- .../IntroduceRepository.java | 10 ++++- .../repository/MasterIntroduceRepository.java | 17 +++++++ .../MasterQuestionRepository.java | 3 +- .../QuestionRepository.java | 3 +- .../introduce/service/IntroduceService.java | 45 ++++++++++++++++++- .../service/MasterIntroduceService.java | 3 ++ .../recruit/infrastructure/RecruitEntity.java | 2 + .../controller/IntroduceControllerTest.java | 3 +- 13 files changed, 125 insertions(+), 19 deletions(-) create mode 100644 src/main/java/umc/kkijuk/server/introduce/controller/response/FindIntroduceResponse.java create mode 100644 src/main/java/umc/kkijuk/server/introduce/controller/response/FindMasterIntroduceResponse.java delete mode 100644 src/main/java/umc/kkijuk/server/introduce/domain/MasterIntroduceRepository.java rename src/main/java/umc/kkijuk/server/introduce/{domain => repository}/IntroduceRepository.java (72%) create mode 100644 src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java rename src/main/java/umc/kkijuk/server/introduce/{domain => repository}/MasterQuestionRepository.java (57%) rename src/main/java/umc/kkijuk/server/introduce/{domain => repository}/QuestionRepository.java (65%) diff --git a/src/main/java/umc/kkijuk/server/dashboard/service/DashBoardServiceImpl.java b/src/main/java/umc/kkijuk/server/dashboard/service/DashBoardServiceImpl.java index ab3bcb85..539fff8b 100644 --- a/src/main/java/umc/kkijuk/server/dashboard/service/DashBoardServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/dashboard/service/DashBoardServiceImpl.java @@ -11,7 +11,7 @@ import umc.kkijuk.server.dashboard.controller.response.IntroduceRemindResponse; import umc.kkijuk.server.dashboard.controller.response.RecruitRemindResponse; import umc.kkijuk.server.introduce.domain.Introduce; -import umc.kkijuk.server.introduce.domain.IntroduceRepository; +import umc.kkijuk.server.introduce.repository.IntroduceRepository; import umc.kkijuk.server.member.domain.Member; import umc.kkijuk.server.recruit.controller.port.RecruitService; import umc.kkijuk.server.recruit.domain.Recruit; 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 d80c70fa..a73279c8 100644 --- a/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java +++ b/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java @@ -11,13 +11,16 @@ import umc.kkijuk.server.introduce.common.BaseResponse; import umc.kkijuk.server.introduce.controller.response.IntroduceListResponse; import umc.kkijuk.server.introduce.controller.response.IntroduceResponse; +import umc.kkijuk.server.introduce.controller.response.MasterIntroduceResponse; import umc.kkijuk.server.introduce.dto.*; import umc.kkijuk.server.introduce.service.IntroduceService; +import umc.kkijuk.server.introduce.service.MasterIntroduceService; import umc.kkijuk.server.login.argumentresolver.Login; import umc.kkijuk.server.login.controller.dto.LoginInfo; import umc.kkijuk.server.member.domain.Member; import umc.kkijuk.server.member.service.MemberService; +import java.util.ArrayList; import java.util.List; @Tag(name = "introduce", description = "자기소개서 API") @@ -26,6 +29,7 @@ @RequestMapping("/history/intro/") public class IntroduceController { private final IntroduceService introduceService; + private final MasterIntroduceService masterIntroduceService; private final MemberService memberService; private final Member requestMember = Member.builder() @@ -90,4 +94,11 @@ public ResponseEntity delete( .body(new BaseResponse<>(HttpStatus.OK.value(), "자기소개서 삭제 완료", intro_Id)); } + @GetMapping("/search") + @Operation(summary = "키워드로 자기소개서 문단 검색") + public ResponseEntity> searchIntroduceByKeyword(@RequestParam String keyword) { + List response = introduceService.searchIntroduceAndMasterByKeyword(keyword); + 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 new file mode 100644 index 00000000..9947a492 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/introduce/controller/response/FindIntroduceResponse.java @@ -0,0 +1,17 @@ +package umc.kkijuk.server.introduce.controller.response; + +import lombok.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Data +@Getter +@Builder +@AllArgsConstructor +public class FindIntroduceResponse { + private Long introId; + private String title; + private String content; + private LocalDateTime 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 new file mode 100644 index 00000000..291429d0 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/introduce/controller/response/FindMasterIntroduceResponse.java @@ -0,0 +1,17 @@ +package umc.kkijuk.server.introduce.controller.response; + +import lombok.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Data +@Getter +@Builder +@AllArgsConstructor +public class FindMasterIntroduceResponse { + private Long masterIntroId; + private String title; + private String content; + private LocalDateTime createdDate; +} diff --git a/src/main/java/umc/kkijuk/server/introduce/domain/MasterIntroduceRepository.java b/src/main/java/umc/kkijuk/server/introduce/domain/MasterIntroduceRepository.java deleted file mode 100644 index 5d05c2ba..00000000 --- a/src/main/java/umc/kkijuk/server/introduce/domain/MasterIntroduceRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package umc.kkijuk.server.introduce.domain; - -import org.springframework.data.jpa.repository.JpaRepository; -import umc.kkijuk.server.introduce.dto.QuestionDto; - -import java.util.List; -import java.util.Optional; - -public interface MasterIntroduceRepository extends JpaRepository { - Optional findByMemberId(Long memberId); -} diff --git a/src/main/java/umc/kkijuk/server/introduce/domain/IntroduceRepository.java b/src/main/java/umc/kkijuk/server/introduce/repository/IntroduceRepository.java similarity index 72% rename from src/main/java/umc/kkijuk/server/introduce/domain/IntroduceRepository.java rename to src/main/java/umc/kkijuk/server/introduce/repository/IntroduceRepository.java index 1bf324ae..feb9f30d 100644 --- a/src/main/java/umc/kkijuk/server/introduce/domain/IntroduceRepository.java +++ b/src/main/java/umc/kkijuk/server/introduce/repository/IntroduceRepository.java @@ -1,4 +1,4 @@ -package umc.kkijuk.server.introduce.domain; +package umc.kkijuk.server.introduce.repository; import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaRepository; @@ -6,6 +6,8 @@ import org.springframework.data.repository.query.Param; import org.springframework.data.domain.Pageable; +import umc.kkijuk.server.introduce.domain.Introduce; + import java.util.List; import java.util.Optional; @@ -16,4 +18,10 @@ public interface IntroduceRepository extends JpaRepository { @Query("SELECT i FROM Introduce i WHERE i.memberId = :memberId AND i.state = :state ORDER BY i.recruit.endTime ASC") Page findByMemberIdAndStateOrderByEndTimeAsc(@Param("memberId") Long memberId, @Param("state") int state, Pageable pageable); + @Query("SELECT i FROM Introduce i " + + "JOIN i.questions q " + + "WHERE q.content LIKE %:keyword%") + List searchIntroduceByKeyword(String keyword); + + } diff --git a/src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java b/src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java new file mode 100644 index 00000000..8141d5d3 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/introduce/repository/MasterIntroduceRepository.java @@ -0,0 +1,17 @@ +package umc.kkijuk.server.introduce.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import umc.kkijuk.server.introduce.domain.MasterIntroduce; + +import java.util.List; +import java.util.Optional; + +public interface MasterIntroduceRepository extends JpaRepository { + Optional findByMemberId(Long memberId); + @Query("SELECT m FROM MasterIntroduce m " + + "JOIN m.masterQuestion mq " + + "WHERE mq.content LIKE %:keyword%") + List searchMasterIntroduceByKeyword(String keyword); +} diff --git a/src/main/java/umc/kkijuk/server/introduce/domain/MasterQuestionRepository.java b/src/main/java/umc/kkijuk/server/introduce/repository/MasterQuestionRepository.java similarity index 57% rename from src/main/java/umc/kkijuk/server/introduce/domain/MasterQuestionRepository.java rename to src/main/java/umc/kkijuk/server/introduce/repository/MasterQuestionRepository.java index bf3eeca5..880fa0f5 100644 --- a/src/main/java/umc/kkijuk/server/introduce/domain/MasterQuestionRepository.java +++ b/src/main/java/umc/kkijuk/server/introduce/repository/MasterQuestionRepository.java @@ -1,6 +1,7 @@ -package umc.kkijuk.server.introduce.domain; +package umc.kkijuk.server.introduce.repository; import org.springframework.data.jpa.repository.JpaRepository; +import umc.kkijuk.server.introduce.domain.MasterQuestion; public interface MasterQuestionRepository extends JpaRepository { } diff --git a/src/main/java/umc/kkijuk/server/introduce/domain/QuestionRepository.java b/src/main/java/umc/kkijuk/server/introduce/repository/QuestionRepository.java similarity index 65% rename from src/main/java/umc/kkijuk/server/introduce/domain/QuestionRepository.java rename to src/main/java/umc/kkijuk/server/introduce/repository/QuestionRepository.java index a25e7a4a..de86d77f 100644 --- a/src/main/java/umc/kkijuk/server/introduce/domain/QuestionRepository.java +++ b/src/main/java/umc/kkijuk/server/introduce/repository/QuestionRepository.java @@ -1,6 +1,7 @@ -package umc.kkijuk.server.introduce.domain; +package umc.kkijuk.server.introduce.repository; import org.springframework.data.jpa.repository.JpaRepository; +import umc.kkijuk.server.introduce.domain.Question; import java.util.List; import java.util.Optional; 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 b862b0fd..a1e3815a 100644 --- a/src/main/java/umc/kkijuk/server/introduce/service/IntroduceService.java +++ b/src/main/java/umc/kkijuk/server/introduce/service/IntroduceService.java @@ -5,17 +5,20 @@ import org.springframework.stereotype.Service; import umc.kkijuk.server.common.domian.exception.IntroFoundException; import umc.kkijuk.server.common.domian.exception.IntroOwnerMismatchException; -import umc.kkijuk.server.common.domian.exception.RecruitOwnerMismatchException; import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException; +import umc.kkijuk.server.introduce.controller.response.FindIntroduceResponse; +import umc.kkijuk.server.introduce.controller.response.FindMasterIntroduceResponse; import umc.kkijuk.server.introduce.controller.response.IntroduceListResponse; import umc.kkijuk.server.introduce.controller.response.IntroduceResponse; import umc.kkijuk.server.introduce.domain.*; import umc.kkijuk.server.introduce.dto.*; +import umc.kkijuk.server.introduce.repository.IntroduceRepository; +import umc.kkijuk.server.introduce.repository.MasterIntroduceRepository; +import umc.kkijuk.server.introduce.repository.QuestionRepository; import umc.kkijuk.server.member.domain.Member; import umc.kkijuk.server.recruit.infrastructure.RecruitEntity; import umc.kkijuk.server.recruit.infrastructure.RecruitJpaRepository; -import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -26,6 +29,7 @@ public class IntroduceService { private final IntroduceRepository introduceRepository; private final RecruitJpaRepository recruitJpaRepository; private final QuestionRepository questionRepository; + private final MasterIntroduceRepository masterIntroduceRepository; @Transactional public IntroduceResponse saveIntro(Member requestMember, Long recruitId, IntroduceReqDto introduceReqDto){ @@ -169,4 +173,41 @@ public List getIntroduceTitles() { .map(opt -> opt.get().toModel().getTitle()) // Get the title of the Recruit .collect(Collectors.toList()); // Collect titles into a List }*/ + + public List searchIntroduceAndMasterByKeyword(String keyword) { + // 자기소개서 검색 + List introduceList = introduceRepository.searchIntroduceByKeyword(keyword) + .stream() + .flatMap(introduce -> introduce.getQuestions().stream() // 각 Question을 개별 항목으로 처리 + .filter(q -> q.getContent().contains(keyword)) // 키워드가 포함된 문단만 필터링 + .map(q -> FindIntroduceResponse.builder() + .introId(introduce.getId()) + .title(q.getTitle()) // 해당 문단의 제목 + .content(q.getContent()) // 해당 문단의 내용 + .createdDate(introduce.getCreatedAt()) // 생성일 + .build())) + .collect(Collectors.toList()); + + // 마스터 자기소개서 검색 + List masterIntroduceList = masterIntroduceRepository.searchMasterIntroduceByKeyword(keyword) + .stream() + .flatMap(masterIntroduce -> masterIntroduce.getMasterQuestion().stream() // 각 MasterQuestion을 개별 항목으로 처리 + .filter(mq -> mq.getContent().contains(keyword)) // 키워드가 포함된 문단만 필터링 + .map(mq -> FindMasterIntroduceResponse.builder() + .masterIntroId(masterIntroduce.getId()) + .title(mq.getTitle()) // 해당 문단의 제목 + .content(mq.getContent()) // 해당 문단의 내용 + .createdDate(masterIntroduce.getCreatedAt()) // 생성일 + .build())) + .collect(Collectors.toList()); + + // 두 리스트를 합쳐서 반환 + List result = new ArrayList<>(); + result.addAll(introduceList); + result.addAll(masterIntroduceList); + + return result; + } + + } diff --git a/src/main/java/umc/kkijuk/server/introduce/service/MasterIntroduceService.java b/src/main/java/umc/kkijuk/server/introduce/service/MasterIntroduceService.java index 5acae91b..dae78b24 100644 --- a/src/main/java/umc/kkijuk/server/introduce/service/MasterIntroduceService.java +++ b/src/main/java/umc/kkijuk/server/introduce/service/MasterIntroduceService.java @@ -10,6 +10,8 @@ import umc.kkijuk.server.introduce.domain.*; import umc.kkijuk.server.introduce.dto.IntroduceReqDto; import umc.kkijuk.server.introduce.dto.QuestionDto; +import umc.kkijuk.server.introduce.repository.MasterIntroduceRepository; +import umc.kkijuk.server.introduce.repository.MasterQuestionRepository; import java.util.ArrayList; import java.util.List; @@ -124,4 +126,5 @@ public MasterIntroduceResponse updateMasterIntro(Long memberId, IntroduceReqDto .build(); } + } diff --git a/src/main/java/umc/kkijuk/server/recruit/infrastructure/RecruitEntity.java b/src/main/java/umc/kkijuk/server/recruit/infrastructure/RecruitEntity.java index 2322deba..1eed0411 100644 --- a/src/main/java/umc/kkijuk/server/recruit/infrastructure/RecruitEntity.java +++ b/src/main/java/umc/kkijuk/server/recruit/infrastructure/RecruitEntity.java @@ -1,6 +1,7 @@ package umc.kkijuk.server.recruit.infrastructure; import jakarta.persistence.*; +import lombok.Getter; import umc.kkijuk.server.common.converter.StringListToStringConverter; import umc.kkijuk.server.recruit.domain.Recruit; import umc.kkijuk.server.recruit.domain.RecruitStatus; @@ -10,6 +11,7 @@ import java.util.List; @Entity +@Getter @Table(name = "recruit") public class RecruitEntity { diff --git a/src/test/java/umc/kkijuk/server/introduce/controller/IntroduceControllerTest.java b/src/test/java/umc/kkijuk/server/introduce/controller/IntroduceControllerTest.java index feb9d109..0f72c23f 100644 --- a/src/test/java/umc/kkijuk/server/introduce/controller/IntroduceControllerTest.java +++ b/src/test/java/umc/kkijuk/server/introduce/controller/IntroduceControllerTest.java @@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -19,6 +18,7 @@ import umc.kkijuk.server.introduce.domain.*; import umc.kkijuk.server.introduce.dto.IntroduceReqDto; import umc.kkijuk.server.introduce.dto.QuestionDto; +import umc.kkijuk.server.introduce.repository.IntroduceRepository; import umc.kkijuk.server.introduce.service.IntroduceService; import umc.kkijuk.server.login.controller.SessionConst; import umc.kkijuk.server.login.controller.dto.LoginInfo; @@ -34,7 +34,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.YearMonth; import java.util.ArrayList; import java.util.Arrays; import java.util.List;