From 88cceb37cbb8b1644f30688a590968c15566f636 Mon Sep 17 00:00:00 2001 From: 5win <94297900+5win@users.noreply.github.com> Date: Sat, 9 Nov 2024 15:05:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=82=A4=EC=9B=8C=EB=93=9C=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(#72)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 활동 조회 API에 키워드 검색 기능 추가 --- .../com/gamsa/activity/controller/ActivityController.java | 2 ++ .../java/com/gamsa/activity/dto/ActivityFilterRequest.java | 3 +++ .../gamsa/activity/repository/ActivityFilterBuilder.java | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/src/main/java/com/gamsa/activity/controller/ActivityController.java b/src/main/java/com/gamsa/activity/controller/ActivityController.java index 13e3fa5..7008f18 100644 --- a/src/main/java/com/gamsa/activity/controller/ActivityController.java +++ b/src/main/java/com/gamsa/activity/controller/ActivityController.java @@ -33,6 +33,7 @@ public Slice findSlice( @RequestParam(required = false) Integer sidoCode, @RequestParam(defaultValue = "false") boolean teenPossibleOnly, @RequestParam(defaultValue = "false") boolean beforeDeadlineOnly, + @RequestParam(required = false) String keyword, Pageable pageable) { ActivityFilterRequest request = ActivityFilterRequest.builder() @@ -41,6 +42,7 @@ public Slice findSlice( .sidoCode(sidoCode) .teenPossibleOnly(teenPossibleOnly) .beforeDeadlineOnly(beforeDeadlineOnly) + .keyword(keyword) .build(); return activityService.findSlice(request, pageable); diff --git a/src/main/java/com/gamsa/activity/dto/ActivityFilterRequest.java b/src/main/java/com/gamsa/activity/dto/ActivityFilterRequest.java index 9be4f9d..e719136 100644 --- a/src/main/java/com/gamsa/activity/dto/ActivityFilterRequest.java +++ b/src/main/java/com/gamsa/activity/dto/ActivityFilterRequest.java @@ -24,4 +24,7 @@ public class ActivityFilterRequest { // 마감되지 않은 활동만 private final boolean beforeDeadlineOnly; + + // 키워드 검색 + private final String keyword; } diff --git a/src/main/java/com/gamsa/activity/repository/ActivityFilterBuilder.java b/src/main/java/com/gamsa/activity/repository/ActivityFilterBuilder.java index c9b83e9..33f6bc2 100644 --- a/src/main/java/com/gamsa/activity/repository/ActivityFilterBuilder.java +++ b/src/main/java/com/gamsa/activity/repository/ActivityFilterBuilder.java @@ -17,6 +17,7 @@ public static BooleanBuilder createFilter(ActivityFilterRequest request) { eqSidoCode(filterBuilder, request.getSidoCode()); isTeenPossibleOnly(filterBuilder, request.isTeenPossibleOnly()); isDeadlineEndOnly(filterBuilder, request.isBeforeDeadlineOnly()); + containsKeyword(filterBuilder, request.getKeyword()); return filterBuilder; } @@ -50,4 +51,10 @@ public static void isDeadlineEndOnly(BooleanBuilder filterBuilder, boolean befor filterBuilder.and(activityJpaEntity.noticeEndDate.after(LocalDateTime.now())); } } + + public static void containsKeyword(BooleanBuilder filterBuilder, String keyword) { + if (keyword != null) { + filterBuilder.and(activityJpaEntity.actTitle.contains(keyword)); + } + } }