From a150ac87270e746cf1beb13bdba379115d4fe860 Mon Sep 17 00:00:00 2001 From: rlarltj Date: Mon, 11 Nov 2024 00:42:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=86=8C=EC=86=8D=EC=9D=84=20keyword?= =?UTF-8?q?=EB=A1=9C=20=EA=B2=80=EC=83=89=ED=95=98=EB=8A=94=20api=EB=A5=BC?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/agency/api/AgencyController.java | 6 +++++ .../repository/AgencyRepositoryCustom.java | 4 ++++ .../repository/AgencyRepositoryImpl.java | 22 +++++++++++++++++++ .../domain/agency/service/AgencyService.java | 10 +++++++++ 4 files changed, 42 insertions(+) diff --git a/src/main/java/com/moneymong/domain/agency/api/AgencyController.java b/src/main/java/com/moneymong/domain/agency/api/AgencyController.java index 185ae1e..9f08b64 100644 --- a/src/main/java/com/moneymong/domain/agency/api/AgencyController.java +++ b/src/main/java/com/moneymong/domain/agency/api/AgencyController.java @@ -47,6 +47,12 @@ public SearchAgencyResponse getAgencyList( return agencyService.getAgencyList(user.getId(), pageable); } + @Operation(summary = "소속 목록 검색") + @GetMapping("/search") + public List searchAgencyList(@RequestParam("keyword") String keyword, @AuthenticationPrincipal JwtAuthentication user) { + return agencyService.search(user.getId(), keyword); + } + @Operation(summary = "소속 내 멤버 목록 조회") @GetMapping("/{agencyId}/agency-users") public AgencyUserResponses getAgencyUserList( diff --git a/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryCustom.java b/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryCustom.java index 2c87a96..0e6dc85 100644 --- a/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryCustom.java +++ b/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryCustom.java @@ -6,8 +6,12 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import java.util.List; + public interface AgencyRepositoryCustom { Page findByUniversityNameByPaging(String universityName, Pageable pageable); Page findByUniversityNameAndAgencyTypeByPaging(String universityName, AgencyType type, Pageable pageable); + + List findByKeyword(String university, String keyword); } diff --git a/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryImpl.java b/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryImpl.java index b2ff304..8112314 100644 --- a/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryImpl.java +++ b/src/main/java/com/moneymong/domain/agency/repository/AgencyRepositoryImpl.java @@ -16,6 +16,7 @@ import java.util.function.Supplier; import static com.moneymong.domain.agency.entity.QAgency.agency; +import static com.moneymong.domain.agency.entity.enums.AgencyType.GENERAL; @Repository @RequiredArgsConstructor @@ -51,6 +52,27 @@ public Page findByUniversityNameAndAgencyTypeByPaging(String universityN } + @Override + public List findByKeyword(String university, String keyword) { + if (keyword == null || keyword.isEmpty()) { + return List.of(); + } + + return queryFactory + .selectFrom(agency) + .distinct() + .where( + agency.agencyType.eq(GENERAL) + .and(agency.agencyName.containsIgnoreCase(keyword)) + .or( + eqUniversityName(university) + .and(agency.agencyName.containsIgnoreCase(keyword)) + ) + ) + .fetch(); + } + + private JPAQuery getCountQuery(String universityName) { return queryFactory.selectFrom(agency) .where(eqUniversityName(universityName)); diff --git a/src/main/java/com/moneymong/domain/agency/service/AgencyService.java b/src/main/java/com/moneymong/domain/agency/service/AgencyService.java index 0cbda14..d81a018 100644 --- a/src/main/java/com/moneymong/domain/agency/service/AgencyService.java +++ b/src/main/java/com/moneymong/domain/agency/service/AgencyService.java @@ -91,6 +91,16 @@ public CreateAgencyResponse create(Long userId, CreateAgencyRequest request) { return new CreateAgencyResponse(agency.getId()); } + @Transactional + public List search(Long userId, String keyword) { + String university = getUniversityName(userId); + List agencies = agencyRepository.findByKeyword(university, keyword); + + return agencies.stream() + .map(AgencyResponse::from) + .toList(); + } + private String getUniversityName(Long userId) { return userUniversityRepository.findByUserId(userId) .map(UserUniversity::getUniversityName)