Skip to content

Commit

Permalink
[FEAT] 장애 유형, 도움 유형에 따른 필터링 기능 구현 (#122)
Browse files Browse the repository at this point in the history
* no change

* feat: 장애 유형 및 도움 유형에 따른 필터링 추가
  • Loading branch information
injae-348 authored Aug 19, 2024
1 parent d44b048 commit 16b4aaa
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 37 deletions.
9 changes: 5 additions & 4 deletions src/main/java/econo/buddybridge/matching/entity/Matching.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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;
Expand All @@ -63,4 +64,4 @@ public void updateMatching(MatchingStatus matchingStatus){
break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -30,9 +32,11 @@ public ApiResponse<ApiResponse.CustomBody<PostCustomPage>> 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);
}

Expand Down
29 changes: 6 additions & 23 deletions src/main/java/econo/buddybridge/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -94,4 +77,4 @@ public void updatePost(PostReqDto postReqDto){
this.content = postReqDto.content();
this.postType = postReqDto.postType();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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;

@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);
}
Original file line number Diff line number Diff line change
@@ -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<PostResDto> 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))
Expand All @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/econo/buddybridge/post/service/PostService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

// 검증 과정 필요성 고려
Expand Down

0 comments on commit 16b4aaa

Please sign in to comment.