Skip to content

Commit

Permalink
v1.4.2 (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 authored Mar 3, 2024
2 parents 6088ab5 + 5437a16 commit c0c72e5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ public ResponseEntity<Void> updatePayment(
adminMemberService.updatePaymentStatus(memberId, request);
return ResponseEntity.ok().build();
}

@Operation(summary = "승인된 회원 전체 조회", description = "승인된 회원 전체를 조회합니다.")
@GetMapping("/granted")
public ResponseEntity<Page<AdminMemberResponse>> getGrantedMembers(
MemberQueryRequest queryRequest, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.findAllGrantedMembers(queryRequest, pageable);
return ResponseEntity.ok().body(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.gdschongik.gdsc.domain.member.application;

import static com.gdschongik.gdsc.domain.member.domain.MemberRole.*;
import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.domain.MemberRole;
import com.gdschongik.gdsc.domain.member.domain.RequirementStatus;
import com.gdschongik.gdsc.domain.member.dto.request.MemberGrantRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberPaymentRequest;
Expand All @@ -30,7 +30,7 @@ public class AdminMemberService {
private final MemberRepository memberRepository;

public Page<AdminMemberResponse> findAll(MemberQueryRequest queryRequest, Pageable pageable) {
Page<Member> members = memberRepository.findAll(queryRequest, pageable);
Page<Member> members = memberRepository.findAllByRole(queryRequest, pageable, null);
return members.map(AdminMemberResponse::from);
}

Expand All @@ -55,7 +55,7 @@ public void updateMember(Long memberId, MemberUpdateRequest request) {
}

public Page<AdminMemberResponse> findAllPendingMembers(MemberQueryRequest queryRequest, Pageable pageable) {
Page<Member> members = memberRepository.findAllByRole(queryRequest, MemberRole.GUEST, pageable);
Page<Member> members = memberRepository.findAllByRole(queryRequest, pageable, GUEST);
return members.map(AdminMemberResponse::from);
}

Expand Down Expand Up @@ -83,4 +83,9 @@ public void updatePaymentStatus(Long memberId, MemberPaymentRequest request) {
Member member = memberRepository.findById(memberId).orElseThrow(() -> new CustomException(MEMBER_NOT_FOUND));
member.updatePaymentStatus(request.status());
}

public Page<AdminMemberResponse> findAllGrantedMembers(MemberQueryRequest queryRequest, Pageable pageable) {
Page<Member> members = memberRepository.findAllByRole(queryRequest, pageable, USER);
return members.map(AdminMemberResponse::from);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
import com.gdschongik.gdsc.domain.member.domain.MemberRole;
import com.gdschongik.gdsc.domain.member.domain.RequirementStatus;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface MemberCustomRepository {
Page<Member> findAll(MemberQueryRequest queryRequest, Pageable pageable);

Optional<Member> findNormalByOauthId(String oauthId);

Page<Member> findAllGrantable(MemberQueryRequest queryRequest, Pageable pageable);

Page<Member> findAllByRole(MemberQueryRequest queryRequest, MemberRole role, Pageable pageable);
Page<Member> findAllByRole(MemberQueryRequest queryRequest, Pageable pageable, @Nullable MemberRole role);

Page<Member> findAllByPaymentStatus(
MemberQueryRequest queryRequest, RequirementStatus paymentStatus, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.querydsl.core.types.dsl.EnumPath;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -30,22 +31,6 @@ public class MemberCustomRepositoryImpl implements MemberCustomRepository {

private final JPAQueryFactory queryFactory;

@Override
public Page<Member> findAll(MemberQueryRequest queryRequest, Pageable pageable) {
List<Member> fetch = queryFactory
.selectFrom(member)
.where(queryOption(queryRequest), eqStatus(MemberStatus.NORMAL))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(member.createdAt.desc())
.fetch();

JPAQuery<Long> countQuery =
queryFactory.select(member.count()).from(member).where(queryOption(queryRequest));

return PageableExecutionUtils.getPage(fetch, pageable, countQuery::fetchOne);
}

@Override
public Optional<Member> findNormalByOauthId(String oauthId) {
return Optional.ofNullable(queryFactory
Expand Down Expand Up @@ -81,10 +66,10 @@ public Page<Member> findAllGrantable(MemberQueryRequest queryRequest, Pageable p
}

@Override
public Page<Member> findAllByRole(MemberQueryRequest queryRequest, MemberRole role, Pageable pageable) {
public Page<Member> findAllByRole(MemberQueryRequest queryRequest, Pageable pageable, @Nullable MemberRole role) {
List<Member> fetch = queryFactory
.selectFrom(member)
.where(queryOption(queryRequest), eqRole(role), eqStatus(MemberStatus.NORMAL))
.where(queryOption(queryRequest), eqRole(role), eqStatus(MemberStatus.NORMAL), isStudentIdNotNull())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(member.createdAt.desc())
Expand All @@ -93,7 +78,7 @@ public Page<Member> findAllByRole(MemberQueryRequest queryRequest, MemberRole ro
JPAQuery<Long> countQuery = queryFactory
.select(member.count())
.from(member)
.where(queryOption(queryRequest), eqRole(role), eqStatus(MemberStatus.NORMAL));
.where(queryOption(queryRequest), eqRole(role), eqStatus(MemberStatus.NORMAL), isStudentIdNotNull());

return PageableExecutionUtils.getPage(fetch, pageable, countQuery::fetchOne);
}
Expand All @@ -119,7 +104,8 @@ public Page<Member> findAllByPaymentStatus(
.where(
queryOption(queryRequest),
eqStatus(MemberStatus.NORMAL),
eqRequirementStatus(member.requirement.paymentStatus, paymentStatus));
eqRequirementStatus(member.requirement.paymentStatus, paymentStatus),
isStudentIdNotNull());

return PageableExecutionUtils.getPage(fetch, pageable, countQuery::fetchOne);
}
Expand All @@ -143,7 +129,7 @@ private Map<Boolean, List<Member>> replaceNullByEmptyList(Map<Boolean, List<Memb
}

private BooleanExpression eqRole(MemberRole role) {
return member.role.eq(role);
return role != null ? member.role.eq(role) : null;
}

private BooleanBuilder requirementVerified() {
Expand Down

0 comments on commit c0c72e5

Please sign in to comment.