Skip to content

Commit

Permalink
refactor: 쿼리옵션 DTO 이름 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
uwoobeat committed Mar 6, 2024
1 parent 8799841 commit 91268ad
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryOption;
import com.gdschongik.gdsc.domain.member.dto.request.MemberUpdateRequest;
import com.gdschongik.gdsc.domain.member.dto.response.AdminMemberResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberGrantResponse;
Expand Down Expand Up @@ -37,8 +37,8 @@ public class AdminMemberController {

@Operation(summary = "전체 회원 목록 조회", description = "전체 회원 목록을 조회합니다.")
@GetMapping
public ResponseEntity<Page<AdminMemberResponse>> getMembers(MemberQueryRequest queryRequest, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.findAll(queryRequest, pageable);
public ResponseEntity<Page<AdminMemberResponse>> getMembers(MemberQueryOption queryOption, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.findAll(queryOption, pageable);
return ResponseEntity.ok().body(response);
}

Expand All @@ -52,8 +52,8 @@ public ResponseEntity<Void> withdrawMember(@PathVariable Long memberId) {
@Operation(summary = "대기중인 회원 목록 조회", description = "대기중인 회원 목록을 조회합니다.")
@GetMapping("/pending")
public ResponseEntity<Page<AdminMemberResponse>> getPendingMembers(
MemberQueryRequest queryRequest, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.findAllPendingMembers(queryRequest, pageable);
MemberQueryOption queryOption, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.findAllPendingMembers(queryOption, pageable);
return ResponseEntity.ok().body(response);
}

Expand All @@ -75,19 +75,19 @@ public ResponseEntity<MemberGrantResponse> grantMember(@Valid @RequestBody Membe
@Operation(summary = "승인 가능 회원 전체 조회", description = "승인 가능한 회원 전체를 조회합니다.")
@GetMapping("/grantable")
public ResponseEntity<Page<AdminMemberResponse>> getGrantableMembers(
MemberQueryRequest queryRequest, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.getGrantableMembers(queryRequest, pageable);
MemberQueryOption queryOption, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.getGrantableMembers(queryOption, pageable);
return ResponseEntity.ok().body(response);
}

@Operation(summary = "회비 납부 상태에 따른 회원 전체 조회", description = "회비 납부 상태에 따라 회원 목록을 조회합니다.")
@GetMapping("/payment")
public ResponseEntity<Page<AdminMemberResponse>> getMembersByPaymentStatus(
MemberQueryRequest queryRequest,
MemberQueryOption queryOption,
@RequestParam(name = "status", required = false) RequirementStatus paymentStatus,
Pageable pageable) {
Page<AdminMemberResponse> response =
adminMemberService.getMembersByPaymentStatus(queryRequest, paymentStatus, pageable);
adminMemberService.getMembersByPaymentStatus(queryOption, paymentStatus, pageable);
return ResponseEntity.ok().body(response);
}

Expand All @@ -102,8 +102,8 @@ public ResponseEntity<Void> updatePayment(
@Operation(summary = "승인된 회원 전체 조회", description = "승인된 회원 전체를 조회합니다.")
@GetMapping("/granted")
public ResponseEntity<Page<AdminMemberResponse>> getGrantedMembers(
MemberQueryRequest queryRequest, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.findAllGrantedMembers(queryRequest, pageable);
MemberQueryOption queryOption, Pageable pageable) {
Page<AdminMemberResponse> response = adminMemberService.findAllGrantedMembers(queryOption, pageable);
return ResponseEntity.ok().body(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryOption;
import com.gdschongik.gdsc.domain.member.dto.request.MemberUpdateRequest;
import com.gdschongik.gdsc.domain.member.dto.response.AdminMemberResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberGrantResponse;
Expand All @@ -32,8 +32,8 @@ public class AdminMemberService {
private final MemberRepository memberRepository;
private final ExcelUtil excelUtil;

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

Expand All @@ -57,8 +57,8 @@ public void updateMember(Long memberId, MemberUpdateRequest request) {
request.nickname());
}

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

Expand All @@ -70,14 +70,14 @@ public MemberGrantResponse grantMember(MemberGrantRequest request) {
return MemberGrantResponse.from(classifiedMember);
}

public Page<AdminMemberResponse> getGrantableMembers(MemberQueryRequest queryRequest, Pageable pageable) {
Page<Member> members = memberRepository.findAllGrantable(queryRequest, pageable);
public Page<AdminMemberResponse> getGrantableMembers(MemberQueryOption queryOption, Pageable pageable) {
Page<Member> members = memberRepository.findAllGrantable(queryOption, pageable);
return members.map(AdminMemberResponse::from);
}

public Page<AdminMemberResponse> getMembersByPaymentStatus(
MemberQueryRequest queryRequest, RequirementStatus paymentStatus, Pageable pageable) {
Page<Member> members = memberRepository.findAllByPaymentStatus(queryRequest, paymentStatus, pageable);
MemberQueryOption queryOption, RequirementStatus paymentStatus, Pageable pageable) {
Page<Member> members = memberRepository.findAllByPaymentStatus(queryOption, paymentStatus, pageable);
return members.map(AdminMemberResponse::from);
}

Expand All @@ -87,8 +87,8 @@ public void updatePaymentStatus(Long memberId, MemberPaymentRequest request) {
member.updatePaymentStatus(request.status());
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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.MemberQueryRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryOption;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;
Expand All @@ -14,12 +14,12 @@
public interface MemberCustomRepository {
Optional<Member> findNormalByOauthId(String oauthId);

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

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

Page<Member> findAllByPaymentStatus(
MemberQueryRequest queryRequest, RequirementStatus paymentStatus, Pageable pageable);
MemberQueryOption queryOption, RequirementStatus paymentStatus, Pageable pageable);

Map<Boolean, List<Member>> groupByVerified(List<Long> memberIdList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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.MemberQueryRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryOption;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.annotation.Nullable;
Expand All @@ -32,10 +32,10 @@ public Optional<Member> findNormalByOauthId(String oauthId) {
}

@Override
public Page<Member> findAllGrantable(MemberQueryRequest queryRequest, Pageable pageable) {
public Page<Member> findAllGrantable(MemberQueryOption queryOption, Pageable pageable) {
List<Member> fetch = queryFactory
.selectFrom(member)
.where(matchesQueryOption(queryRequest), eqRole(MemberRole.GUEST), isGrantAvailable())
.where(matchesQueryOption(queryOption), eqRole(MemberRole.GUEST), isGrantAvailable())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(member.createdAt.desc())
Expand All @@ -44,16 +44,16 @@ public Page<Member> findAllGrantable(MemberQueryRequest queryRequest, Pageable p
JPAQuery<Long> countQuery = queryFactory
.select(member.count())
.from(member)
.where(matchesQueryOption(queryRequest), eqRole(MemberRole.GUEST), isGrantAvailable());
.where(matchesQueryOption(queryOption), eqRole(MemberRole.GUEST), isGrantAvailable());

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

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

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

@Override
public Page<Member> findAllByPaymentStatus(
MemberQueryRequest queryRequest, RequirementStatus paymentStatus, Pageable pageable) {
MemberQueryOption queryOption, RequirementStatus paymentStatus, Pageable pageable) {
List<Member> fetch = queryFactory
.selectFrom(member)
.where(
matchesQueryOption(queryRequest),
matchesQueryOption(queryOption),
eqRequirementStatus(member.requirement.paymentStatus, paymentStatus),
isStudentIdNotNull())
.offset(pageable.getOffset())
Expand All @@ -85,7 +85,7 @@ public Page<Member> findAllByPaymentStatus(
.select(member.count())
.from(member)
.where(
matchesQueryOption(queryRequest),
matchesQueryOption(queryOption),
eqRequirementStatus(member.requirement.paymentStatus, paymentStatus),
isStudentIdNotNull());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.gdschongik.gdsc.domain.member.domain.Department;
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 com.gdschongik.gdsc.domain.member.dto.request.MemberQueryOption;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.EnumPath;
Expand Down Expand Up @@ -67,14 +67,14 @@ protected BooleanBuilder isGrantAvailable() {
.and(eqRequirementStatus(member.requirement.bevyStatus, VERIFIED));
}

protected BooleanBuilder matchesQueryOption(MemberQueryRequest queryRequest) {
protected BooleanBuilder matchesQueryOption(MemberQueryOption queryOption) {
return new BooleanBuilder()
.and(eqStudentId(queryRequest.studentId()))
.and(eqName(queryRequest.name()))
.and(eqPhone(queryRequest.phone()))
.and(inDepartmentList(Department.searchDepartments(queryRequest.department())))
.and(eqEmail(queryRequest.email()))
.and(eqDiscordUsername(queryRequest.discordUsername()))
.and(eqNickname(queryRequest.nickname()));
.and(eqStudentId(queryOption.studentId()))
.and(eqName(queryOption.name()))
.and(eqPhone(queryOption.phone()))
.and(inDepartmentList(Department.searchDepartments(queryOption.department())))
.and(eqEmail(queryOption.email()))
.and(eqDiscordUsername(queryOption.discordUsername()))
.and(eqNickname(queryOption.nickname()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

public record MemberQueryRequest(
public record MemberQueryOption(
@Schema(description = "학번", pattern = STUDENT_ID) String studentId,
@Schema(description = "이름") String name,
@Schema(description = "전화번호", pattern = PHONE_WITHOUT_HYPHEN) String phone,
Expand Down

0 comments on commit 91268ad

Please sign in to comment.