Skip to content

Commit

Permalink
[FEAT] AssistanceType 생활, 교육에서 학습, 식사, 이동 으로 변경, 다중 필터링 적용 (#179)
Browse files Browse the repository at this point in the history
feat: AssistanceType 생활, 교육 -> 학습, 식사, 이동 변경 + 다중 필터링 적용
  • Loading branch information
injae-348 authored Oct 7, 2024
1 parent 81f9e56 commit 6ed567c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ApiResponse<ApiResponse.CustomBody<PostCustomPage>> getAllPosts(
@RequestParam(defaultValue = "desc", required = false) String sort,
@RequestParam(value = "post-status", required = false) PostStatus postStatus,
@RequestParam(value = "disability-type", required = false) List<DisabilityType> disabilityType,
@RequestParam(value = "assistance-type", required = false) AssistanceType assistanceType,
@RequestParam(value = "assistance-type", required = false) List<AssistanceType> assistanceType,
HttpServletRequest request
) {
Long memberId = SessionUtils.getMemberId(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

@Getter
public enum AssistanceType {
교육("교육"),
생활("생활");
학습("학습"),
식사("식사"),
이동("이동");

private final String assistanceType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> disabilityType, AssistanceType assistanceType);
PostStatus postStatus, List<DisabilityType> disabilityType, List<AssistanceType> assistanceType);

PostCustomPage findPostsMyPage(Long memberId, Integer page, Integer size, String sort, PostType postType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> disabilityType, AssistanceType assistanceType) {
PostStatus postStatus, List<DisabilityType> disabilityType, List<AssistanceType> assistanceType) {

List<Post> 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))
Expand All @@ -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);
Expand Down Expand Up @@ -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<AssistanceType> assistanceTypes) {
if (assistanceTypes == null || assistanceTypes.isEmpty()) {
return null;
}
return post.assistanceType.in(assistanceTypes);
}

private OrderSpecifier<?> buildOrderSpecifier(String sort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> disabilityType, AssistanceType assistanceType) {
List<DisabilityType> disabilityType, List<AssistanceType> assistanceType) {
return postRepository.findPosts(memberId, page - 1, size, sort, postType, postStatus, disabilityType, assistanceType);
}

Expand Down

0 comments on commit 6ed567c

Please sign in to comment.