From 16b4aaa976a2452adbe57700a42a7645b9014838 Mon Sep 17 00:00:00 2001 From: JeongInJae <93825184+injae-348@users.noreply.github.com> Date: Mon, 19 Aug 2024 20:23:04 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EC=9E=A5=EC=95=A0=20=EC=9C=A0?= =?UTF-8?q?=ED=98=95,=20=EB=8F=84=EC=9B=80=20=EC=9C=A0=ED=98=95=EC=97=90?= =?UTF-8?q?=20=EB=94=B0=EB=A5=B8=20=ED=95=84=ED=84=B0=EB=A7=81=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=20(#122)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * no change * feat: 장애 유형 및 도움 유형에 따른 필터링 추가 --- .../buddybridge/matching/entity/Matching.java | 9 +++--- .../post/controller/PostController.java | 8 +++-- .../econo/buddybridge/post/entity/Post.java | 29 ++++------------- .../post/repository/PostRepositoryCustom.java | 5 ++- .../post/repository/PostRepositoryImpl.java | 31 ++++++++++++++++--- .../buddybridge/post/service/PostService.java | 7 +++-- 6 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/main/java/econo/buddybridge/matching/entity/Matching.java b/src/main/java/econo/buddybridge/matching/entity/Matching.java index ae8b178..c2ceee3 100644 --- a/src/main/java/econo/buddybridge/matching/entity/Matching.java +++ b/src/main/java/econo/buddybridge/matching/entity/Matching.java @@ -6,13 +6,14 @@ import econo.buddybridge.post.entity.Post; import econo.buddybridge.post.entity.PostStatus; import jakarta.persistence.*; -import java.util.ArrayList; -import java.util.List; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @Table(name = "MATCHING") @@ -50,7 +51,7 @@ public Matching(Post post, Member taker, Member giver, MatchingStatus matchingSt this.giver = giver; this.matchingStatus = matchingStatus; } - + // 매칭 상태 변경 public void updateMatching(MatchingStatus matchingStatus){ this.matchingStatus = matchingStatus; @@ -63,4 +64,4 @@ public void updateMatching(MatchingStatus matchingStatus){ break; } } -} +} \ No newline at end of file diff --git a/src/main/java/econo/buddybridge/post/controller/PostController.java b/src/main/java/econo/buddybridge/post/controller/PostController.java index 3e7e32e..2592643 100644 --- a/src/main/java/econo/buddybridge/post/controller/PostController.java +++ b/src/main/java/econo/buddybridge/post/controller/PostController.java @@ -1,9 +1,11 @@ package econo.buddybridge.post.controller; import econo.buddybridge.common.annotation.AllowAnonymous; +import econo.buddybridge.member.entity.DisabilityType; import econo.buddybridge.post.dto.PostCustomPage; import econo.buddybridge.post.dto.PostReqDto; import econo.buddybridge.post.dto.PostResDto; +import econo.buddybridge.post.entity.AssistanceType; import econo.buddybridge.post.entity.PostStatus; import econo.buddybridge.post.entity.PostType; import econo.buddybridge.post.service.PostService; @@ -30,9 +32,11 @@ public ApiResponse> getAllPosts( @RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam(defaultValue = "desc", required = false) String sort, - @RequestParam(value = "post-status", required = false) PostStatus postStatus + @RequestParam(value = "post-status", required = false) PostStatus postStatus, + @RequestParam(value = "disability-type", required = false) DisabilityType disabilityType, + @RequestParam(value = "assistance-type", required = false) AssistanceType assistanceType ) { - PostCustomPage posts = postService.getPosts(page, size, sort, postType, postStatus); + PostCustomPage posts = postService.getPosts(page, size, sort, postType, postStatus, disabilityType, assistanceType); return ApiResponseGenerator.success(posts, HttpStatus.OK); } diff --git a/src/main/java/econo/buddybridge/post/entity/Post.java b/src/main/java/econo/buddybridge/post/entity/Post.java index 91f4af6..a2ea0e8 100644 --- a/src/main/java/econo/buddybridge/post/entity/Post.java +++ b/src/main/java/econo/buddybridge/post/entity/Post.java @@ -7,31 +7,14 @@ import econo.buddybridge.member.entity.DisabilityType; import econo.buddybridge.member.entity.Member; import econo.buddybridge.post.dto.PostReqDto; -import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; -import jakarta.persistence.Embedded; -import jakarta.persistence.Entity; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import java.util.ArrayList; -import java.util.List; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; +import jakarta.persistence.*; +import lombok.*; import lombok.Builder.Default; -import lombok.Getter; -import lombok.NoArgsConstructor; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @Table(name = "POST") @@ -94,4 +77,4 @@ public void updatePost(PostReqDto postReqDto){ this.content = postReqDto.content(); this.postType = postReqDto.postType(); } -} +} \ No newline at end of file diff --git a/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java b/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java index 6328525..48232ec 100644 --- a/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java +++ b/src/main/java/econo/buddybridge/post/repository/PostRepositoryCustom.java @@ -1,6 +1,8 @@ package econo.buddybridge.post.repository; +import econo.buddybridge.member.entity.DisabilityType; import econo.buddybridge.post.dto.PostCustomPage; +import econo.buddybridge.post.entity.AssistanceType; import econo.buddybridge.post.entity.PostStatus; import econo.buddybridge.post.entity.PostType; import org.springframework.stereotype.Repository; @@ -8,5 +10,6 @@ @Repository public interface PostRepositoryCustom { - PostCustomPage findPosts(Integer page, Integer size, String sort, PostType postType, PostStatus postStatus); + PostCustomPage findPosts(Integer page, Integer size, String sort, PostType postType, + PostStatus postStatus, DisabilityType disabilityType, AssistanceType assistanceType); } diff --git a/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java b/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java index b5d3c03..790fa05 100644 --- a/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java +++ b/src/main/java/econo/buddybridge/post/repository/PostRepositoryImpl.java @@ -1,27 +1,32 @@ package econo.buddybridge.post.repository; -import static econo.buddybridge.post.entity.QPost.post; - import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import econo.buddybridge.member.entity.DisabilityType; import econo.buddybridge.post.dto.PostCustomPage; import econo.buddybridge.post.dto.PostResDto; +import econo.buddybridge.post.entity.AssistanceType; +import econo.buddybridge.post.entity.District; import econo.buddybridge.post.entity.PostStatus; import econo.buddybridge.post.entity.PostType; -import java.util.List; import lombok.RequiredArgsConstructor; +import java.util.List; + +import static econo.buddybridge.post.entity.QPost.post; + @RequiredArgsConstructor public class PostRepositoryImpl implements PostRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public PostCustomPage findPosts(Integer page, Integer size, String sort, PostType postType, PostStatus postStatus) { + public PostCustomPage findPosts(Integer page, Integer size, String sort, PostType postType, PostStatus postStatus, DisabilityType disabilityType, AssistanceType assistanceType) { List postResDtos = queryFactory .selectFrom(post) - .where(buildPostStatusExpression(postStatus), buildPostTypeExpression(postType)) + .where(buildPostStatusExpression(postStatus), buildPostTypeExpression(postType), + buildPostDisabilityTypeExpression(disabilityType), buildPostAssistanceTypeExpression(assistanceType)) .offset((long) page * size) .limit(size) .orderBy(buildOrderSpecifier(sort)) @@ -48,6 +53,22 @@ private BooleanExpression buildPostStatusExpression(PostStatus postStatus) { return postStatus == null ? null : post.postStatus.eq(postStatus); } + // 없음, 시각장애, 청각장애, 지적장애, 지체장애, 자폐성장애, 뇌병변장애, 정신장애 + private BooleanExpression buildPostDisabilityTypeExpression(DisabilityType disabilityType) { +// return disabilityType == null ? null : post.disabilityType.eq(disabilityType); + return disabilityType == null ? null : post.author.disabilityType.eq(disabilityType); + } + + // 광주광역시, 남구, 북구, 서구, 동구, 광산구 + 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 OrderSpecifier buildOrderSpecifier(String sort) { return switch (sort.toLowerCase()) { case "desc" -> post.createdAt.desc(); diff --git a/src/main/java/econo/buddybridge/post/service/PostService.java b/src/main/java/econo/buddybridge/post/service/PostService.java index ee271e1..c8db3a6 100644 --- a/src/main/java/econo/buddybridge/post/service/PostService.java +++ b/src/main/java/econo/buddybridge/post/service/PostService.java @@ -1,10 +1,12 @@ package econo.buddybridge.post.service; +import econo.buddybridge.member.entity.DisabilityType; import econo.buddybridge.member.entity.Member; import econo.buddybridge.member.service.MemberService; import econo.buddybridge.post.dto.PostCustomPage; import econo.buddybridge.post.dto.PostReqDto; import econo.buddybridge.post.dto.PostResDto; +import econo.buddybridge.post.entity.AssistanceType; import econo.buddybridge.post.entity.Post; import econo.buddybridge.post.entity.PostStatus; import econo.buddybridge.post.entity.PostType; @@ -31,8 +33,9 @@ public PostResDto findPost(Long postId) { } @Transactional(readOnly = true) - public PostCustomPage getPosts(Integer page, Integer size, String sort, PostType postType, PostStatus postStatus) { - return postRepositoryCustom.findPosts(page - 1, size, sort, postType, postStatus); + public PostCustomPage getPosts(Integer page, Integer size, String sort, PostType postType, PostStatus postStatus, + DisabilityType disabilityType, AssistanceType assistanceType) { + return postRepositoryCustom.findPosts(page - 1, size, sort, postType, postStatus, disabilityType, assistanceType); } // 검증 과정 필요성 고려