From 31d0ad82fcd2307d5e91ca632c6f165789385f7f Mon Sep 17 00:00:00 2001 From: jiiiiiw <98935125+jiiiiiw@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:55:49 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=EC=A0=84=EC=88=A0=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=ED=8C=90=20=EA=B2=80=EC=83=89=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#163)=20(#164)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ feat: TacticController에 전술검색 api 추가 (#163) * ✨ feat: TacticQueryService에 전술검색 로직 구현 (#163) * ✨ feat: TacticRepository에 전술검색 JPA 쿼리 메서드 추가 (#163) --- .../domain/tactic/controller/TacticController.java | 11 +++++++++++ .../domain/tactic/repository/TacticRepository.java | 1 + .../domain/tactic/service/TacticQueryService.java | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java b/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java index 508dc16d..f94a16b1 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java @@ -53,6 +53,17 @@ public ApiResponse> getUserTactic( return ApiResponse.onSuccess(userTacticLists); } + @Operation(summary = "제목으로 전술 검색", description = "제목으로 전술을 검색합니다. 단, 공개(anonymous가 false) 인 전술만 검색가능. 페이징 적용, 생성 날짜 기준 내림차순 정렬.") + @GetMapping("/search") + public ApiResponse> searchTitle( + @RequestParam(value ="title",required = false) String title, + @RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "10") int size) { + Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt")); + Page tacticLists = tacticQueryService.searchByTitle(title, pageable); + return ApiResponse.onSuccess(tacticLists); + } + @Operation(summary = "전술 생성", description = "전술을 생성합니다. 프로필이 생성이 된 후에 작성 가능.") @PostMapping public ApiResponse createTactic(@Valid @RequestBody TacticCreateRequest request, @LoginUser User user){ diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/repository/TacticRepository.java b/src/main/java/com/capstone/BnagFer/domain/tactic/repository/TacticRepository.java index 1337307b..4c40cce8 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/repository/TacticRepository.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/repository/TacticRepository.java @@ -16,4 +16,5 @@ public interface TacticRepository extends JpaRepository { Page findAllByAnonymousFalse(Pageable pageable); Page findAllByUser(User user, Pageable pageable); + Page findByTacticNameContainingAndAnonymousFalse(String title, Pageable pageable); } diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java b/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java index 10442b45..b3027e9b 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticQueryService.java @@ -51,4 +51,11 @@ public TacticDetailResponse getTacticById(Long tacticId) { return TacticDetailResponse.from(tactic, likeCount, commentCount); } + + public Page searchByTitle(String title, Pageable pageable) { + if (title == null) title = ""; + + Page byTitleContaining = tacticRepository.findByTacticNameContainingAndAnonymousFalse(title, pageable); + return byTitleContaining.map(TacticResponse.TacticList::from); + } }