From 47c34e7bd643fa07d6e3f319fa2b28f57f2df993 Mon Sep 17 00:00:00 2001 From: hyeonda02 Date: Sat, 9 Nov 2024 16:39:22 +0900 Subject: [PATCH] =?UTF-8?q?Feat=20:=20=ED=99=9C=EB=8F=99=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20-=20?= =?UTF-8?q?=ED=99=9C=EB=8F=99=EB=AA=85=EC=97=90=20=ED=8A=B9=EC=A0=95=20key?= =?UTF-8?q?word=EA=B0=80=20=ED=8F=AC=ED=95=A8=EB=90=9C=20=ED=99=9C?= =?UTF-8?q?=EB=8F=99=20=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BaseCareerController.java | 16 ++++++++++ .../response/FindCareerResponse.java | 30 +++++++++++++++++++ .../career/repository/ActivityRepository.java | 1 + .../career/repository/CircleRepository.java | 1 + .../repository/CompetitionRepository.java | 1 + .../repository/EduCareerRepository.java | 1 + .../repository/EmploymentRepository.java | 1 + .../career/repository/ProjectRepository.java | 1 + .../career/service/BaseCareerService.java | 2 ++ .../career/service/BaseCareerServiceImpl.java | 21 +++++++++++-- 10 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java diff --git a/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java b/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java index c3cacbfc..92dd2448 100644 --- a/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java +++ b/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java @@ -305,5 +305,21 @@ public CareerResponse> findTagAndDetail( baseCareerService.findAllDetailByTag(requestMember, tagId, sort) ); } + @GetMapping("/find") + @Operation( + summary = "활동 검색 - 활동", + description = "활동을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 주세요. " ) + public CareerResponse> findCareerWithKeyword( + @Login LoginInfo loginInfo, + @RequestParam(name = "keyword") String keyword, + @RequestParam(name = "sort") String sort + ){ + Member requestMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findCareerWithKeyword(requestMember, keyword, sort) + ); + + } } diff --git a/src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java b/src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java new file mode 100644 index 00000000..03832605 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java @@ -0,0 +1,30 @@ +package umc.kkijuk.server.career.controller.response; + +import lombok.*; +import umc.kkijuk.server.career.domain.BaseCareer; + +import java.time.LocalDate; + +@Data +@Getter +@Setter +@Builder +@AllArgsConstructor +public class FindCareerResponse { + private Long careerId; + private String careerType; + private String careerTitle; + private String careerAlias; + private LocalDate startdate; + private LocalDate enddate; + + public FindCareerResponse(BaseCareer career, String careerType){ + this.careerId = career.getId(); + this.careerType = careerType; + this.careerTitle = career.getName(); + this.careerAlias = career.getAlias(); + this.startdate = career.getStartdate(); + this.enddate = career.getEnddate(); + } + +} diff --git a/src/main/java/umc/kkijuk/server/career/repository/ActivityRepository.java b/src/main/java/umc/kkijuk/server/career/repository/ActivityRepository.java index 2a2dd751..20813cbe 100644 --- a/src/main/java/umc/kkijuk/server/career/repository/ActivityRepository.java +++ b/src/main/java/umc/kkijuk/server/career/repository/ActivityRepository.java @@ -7,4 +7,5 @@ public interface ActivityRepository extends JpaRepository { List findByMemberId(Long memberId); + List findByMemberIdAndNameContaining(Long memberId, String keyword); } diff --git a/src/main/java/umc/kkijuk/server/career/repository/CircleRepository.java b/src/main/java/umc/kkijuk/server/career/repository/CircleRepository.java index b8fb26cd..d4f8acc5 100644 --- a/src/main/java/umc/kkijuk/server/career/repository/CircleRepository.java +++ b/src/main/java/umc/kkijuk/server/career/repository/CircleRepository.java @@ -7,4 +7,5 @@ public interface CircleRepository extends JpaRepository { List findByMemberId(Long memberId); + List findByMemberIdAndNameContaining(Long memberId, String keyword); } diff --git a/src/main/java/umc/kkijuk/server/career/repository/CompetitionRepository.java b/src/main/java/umc/kkijuk/server/career/repository/CompetitionRepository.java index 0f03f027..0e01d190 100644 --- a/src/main/java/umc/kkijuk/server/career/repository/CompetitionRepository.java +++ b/src/main/java/umc/kkijuk/server/career/repository/CompetitionRepository.java @@ -7,4 +7,5 @@ public interface CompetitionRepository extends JpaRepository { List findByMemberId(Long memberId); + List findByMemberIdAndNameContaining(Long memberId, String keyword); } diff --git a/src/main/java/umc/kkijuk/server/career/repository/EduCareerRepository.java b/src/main/java/umc/kkijuk/server/career/repository/EduCareerRepository.java index 7137c4d6..b9cdca8c 100644 --- a/src/main/java/umc/kkijuk/server/career/repository/EduCareerRepository.java +++ b/src/main/java/umc/kkijuk/server/career/repository/EduCareerRepository.java @@ -7,4 +7,5 @@ public interface EduCareerRepository extends JpaRepository { List findByMemberId(Long memberId); + List findByMemberIdAndNameContaining(Long memberId, String keyword); } diff --git a/src/main/java/umc/kkijuk/server/career/repository/EmploymentRepository.java b/src/main/java/umc/kkijuk/server/career/repository/EmploymentRepository.java index f9e753ea..1b72b64f 100644 --- a/src/main/java/umc/kkijuk/server/career/repository/EmploymentRepository.java +++ b/src/main/java/umc/kkijuk/server/career/repository/EmploymentRepository.java @@ -7,4 +7,5 @@ public interface EmploymentRepository extends JpaRepository { List findByMemberId(Long memberId); + List findByMemberIdAndNameContaining(Long memberId, String keyword); } diff --git a/src/main/java/umc/kkijuk/server/career/repository/ProjectRepository.java b/src/main/java/umc/kkijuk/server/career/repository/ProjectRepository.java index 8c2bbcdc..1c6aeedc 100644 --- a/src/main/java/umc/kkijuk/server/career/repository/ProjectRepository.java +++ b/src/main/java/umc/kkijuk/server/career/repository/ProjectRepository.java @@ -7,4 +7,5 @@ public interface ProjectRepository extends JpaRepository { List findByMemberId(Long memberId); + List findByMemberIdAndNameContaining(Long memberId, String keyword); } diff --git a/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java b/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java index c43b78bd..07b545d1 100644 --- a/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java +++ b/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java @@ -56,4 +56,6 @@ public interface BaseCareerService { List findAllTag(Member requestMember, String keyword); List findAllDetailByTag(Member requestMember, Long tagId, String sort); + + List findCareerWithKeyword(Member requestMember, String keyword, String sort); } diff --git a/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java b/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java index 58adaf48..b83a08a7 100644 --- a/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java @@ -21,7 +21,6 @@ import java.time.LocalDate; import java.util.*; import java.util.function.BiFunction; -import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -505,9 +504,27 @@ public List findAllDetailByTag(Member requestMember, Long ta return buildDetailResponse(detailList, sort); } + @Override + public List findCareerWithKeyword(Member requestMember, String keyword, String sort) { + List careers = new ArrayList<>(); + careers.addAll(activityRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword)); + careers.addAll(eduCareerRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword)); + careers.addAll(employmentRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword)); + careers.addAll(circleRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword)); + careers.addAll(projectRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword)); + careers.addAll(competitionRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword)); + + if ("new".equalsIgnoreCase(sort)) { + careers.sort(Comparator.comparing(BaseCareer::getEnddate).reversed()); + } else { + careers.sort(Comparator.comparing(BaseCareer::getEnddate)); + } + return careers.stream().limit(2) + .map(career -> new FindCareerResponse(career, career.getClass().getSimpleName())) + .collect(Collectors.toList()); - + } private List buildDetailResponse(List detailList, String sort) {