From 6ed567c264bf6348a4220a7d4924e4f401a377e8 Mon Sep 17 00:00:00 2001 From: JeongInJae <93825184+injae-348@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:31:48 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20AssistanceType=20=EC=83=9D=ED=99=9C,?= =?UTF-8?q?=20=EA=B5=90=EC=9C=A1=EC=97=90=EC=84=9C=20=ED=95=99=EC=8A=B5,?= =?UTF-8?q?=20=EC=8B=9D=EC=82=AC,=20=EC=9D=B4=EB=8F=99=20=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20=EB=8B=A4=EC=A4=91=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EB=A7=81=20=EC=A0=81=EC=9A=A9=20(#179)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: AssistanceType 생활, 교육 -> 학습, 식사, 이동 변경 + 다중 필터링 적용 --- .../post/controller/PostController.java | 2 +- .../buddybridge/post/entity/AssistanceType.java | 5 +++-- .../post/repository/PostRepositoryCustom.java | 2 +- .../post/repository/PostRepositoryImpl.java | 15 +++++++++------ .../buddybridge/post/service/PostService.java | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/econo/buddybridge/post/controller/PostController.java b/src/main/java/econo/buddybridge/post/controller/PostController.java index a7abf7e..0b4eaf0 100644 --- a/src/main/java/econo/buddybridge/post/controller/PostController.java +++ b/src/main/java/econo/buddybridge/post/controller/PostController.java @@ -64,7 +64,7 @@ public ApiResponse> getAllPosts( @RequestParam(defaultValue = "desc", required = false) String sort, @RequestParam(value = "post-status", required = false) PostStatus postStatus, @RequestParam(value = "disability-type", required = false) List disabilityType, - @RequestParam(value = "assistance-type", required = false) AssistanceType assistanceType, + @RequestParam(value = "assistance-type", required = false) List assistanceType, HttpServletRequest request ) { Long memberId = SessionUtils.getMemberId(request); diff --git a/src/main/java/econo/buddybridge/post/entity/AssistanceType.java b/src/main/java/econo/buddybridge/post/entity/AssistanceType.java index 38e289b..4fc3911 100644 --- a/src/main/java/econo/buddybridge/post/entity/AssistanceType.java +++ b/src/main/java/econo/buddybridge/post/entity/AssistanceType.java @@ -4,8 +4,9 @@ @Getter public enum AssistanceType { - 교육("교육"), - 생활("생활"); + 학습("학습"), + 식사("식사"), + 이동("이동"); private final String assistanceType; diff --git a/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java b/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java index abd1641..bbeac0f 100644 --- a/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java +++ b/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java @@ -13,7 +13,7 @@ public interface PostRepositoryCustom { PostResDto findByMemberIdAndPostId(Long memberId, Long postId); PostCustomPage findPosts(Long memberId, Integer page, Integer size, String sort, PostType postType, - PostStatus postStatus, List disabilityType, AssistanceType assistanceType); + PostStatus postStatus, List disabilityType, List assistanceType); PostCustomPage findPostsMyPage(Long memberId, Integer page, Integer size, String sort, PostType postType); } diff --git a/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java b/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java index b66523a..f7c1dac 100644 --- a/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java +++ b/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java @@ -50,12 +50,12 @@ public PostResDto findByMemberIdAndPostId(Long memberId, Long postId) { @Override public PostCustomPage findPosts(Long memberId, Integer page, Integer size, String sort, PostType postType, - PostStatus postStatus, List disabilityType, AssistanceType assistanceType) { + PostStatus postStatus, List disabilityType, List assistanceType) { List posts = queryFactory .selectFrom(post) .where(buildPostStatusExpression(postStatus), buildPostTypeExpression(postType), - buildPostDisabilityTypesExpression(disabilityType), buildPostAssistanceTypeExpression(assistanceType)) + buildPostDisabilityTypesExpression(disabilityType), buildPostAssistanceTypesExpression(assistanceType)) .offset((long) page * size) .limit(size) .orderBy(buildOrderSpecifier(sort)) @@ -67,7 +67,7 @@ public PostCustomPage findPosts(Long memberId, Integer page, Integer size, Strin .select(post.count()) .from(post) .where(buildPostStatusExpression(postStatus), buildPostTypeExpression(postType), - buildPostDisabilityTypesExpression(disabilityType), buildPostAssistanceTypeExpression(assistanceType)) + buildPostDisabilityTypesExpression(disabilityType), buildPostAssistanceTypesExpression(assistanceType)) .fetchOne(); return new PostCustomPage(content, totalElements, content.size() < size); @@ -142,9 +142,12 @@ private BooleanExpression buildPostDistrictExpression(District district) { return district == null ? null : post.district.eq(district); } - // 교육, 생활 - private BooleanExpression buildPostAssistanceTypeExpression(AssistanceType assistanceType) { - return assistanceType == null ? null : post.assistanceType.eq(assistanceType); + // 학습, 식사, 이동 + private BooleanExpression buildPostAssistanceTypesExpression(List assistanceTypes) { + if (assistanceTypes == null || assistanceTypes.isEmpty()) { + return null; + } + return post.assistanceType.in(assistanceTypes); } private OrderSpecifier buildOrderSpecifier(String sort) { diff --git a/src/main/java/econo/buddybridge/post/service/PostService.java b/src/main/java/econo/buddybridge/post/service/PostService.java index 510f888..a01fc96 100644 --- a/src/main/java/econo/buddybridge/post/service/PostService.java +++ b/src/main/java/econo/buddybridge/post/service/PostService.java @@ -48,7 +48,7 @@ public PostCustomPage getPostsMyPage(Long memberId, Integer page, Integer size, @Transactional(readOnly = true) // 전체 게시글 조회 public PostCustomPage getPosts(Long memberId, Integer page, Integer size, String sort, PostType postType, PostStatus postStatus, - List disabilityType, AssistanceType assistanceType) { + List disabilityType, List assistanceType) { return postRepository.findPosts(memberId, page - 1, size, sort, postType, postStatus, disabilityType, assistanceType); }