-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 어드민 멤버 조회하기 API 구현 #37
Merged
Merged
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8eef013
feat: AdminMemberController 추가
Sangwook02 fdfcce2
feat: 어드민 멤버 조회 기능 구현
Sangwook02 44c7744
feat: 멤버 조회 서비스 구현
Sangwook02 e79e515
feat: 멤버 조회 응답 dto 추가
Sangwook02 18b1e22
feat: 멤버 조회 레포지토리 구현
Sangwook02 223a17e
feat: 쿼리 파라미터 예외 추가
Sangwook02 9a0eea5
fix: 메서드 이름 수정
Sangwook02 9d49cd9
test: 유효하지 않은 검색 조건에 대한 테스트 추가
Sangwook02 1e034a3
feat: 쿼리 조건을 처리하는 enum 타입 추가
Sangwook02 94cd707
refactor: 서비스 레이어에서 검색 조건을 처리하도록 수정
Sangwook02 7f4cbb8
test: 로직 변경에 따른 테스트 수정
Sangwook02 f090c40
refactor: 검색 조건의 형식을 수정
Sangwook02 ca1166b
remove: 사용하지 않는 Enum 타입 제거
Sangwook02 939fe95
remove: 로직 변경에 따른 테스트 제거
Sangwook02 979d913
refactor: 검색 조건 로직 수정
Sangwook02 149c8b4
feat: 검색 조건 전달 dto 추가
Sangwook02 b0d5931
Merge branch 'develop' of https://github.com/GDSC-Hongik/gdsc-server …
Sangwook02 051e1e7
refactor: 불필요한 정적 팩토리 메서드 제거
Sangwook02 9ed344a
refactor: read-only 속성 부여
Sangwook02 c17940c
refactor: read-only 속성 클래스 레벨로 변경
Sangwook02 e12f664
rename: dto 이름 변경
Sangwook02 4435ad1
style: spotless apply
Sangwook02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/gdschongik/gdsc/domain/member/api/AdminMemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.gdschongik.gdsc.domain.member.api; | ||
|
||
import com.gdschongik.gdsc.domain.member.application.MemberService; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest; | ||
import com.gdschongik.gdsc.domain.member.dto.response.AdminMemberFindAllResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/admin/members") | ||
@RequiredArgsConstructor | ||
public class AdminMemberController { | ||
|
||
private final MemberService memberService; | ||
|
||
@GetMapping | ||
public ResponseEntity<Page<AdminMemberFindAllResponse>> getMembers( | ||
MemberQueryRequest queryRequest, Pageable pageable) { | ||
Page<AdminMemberFindAllResponse> response = memberService.findAll(queryRequest, pageable); | ||
return ResponseEntity.ok().body(response); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/gdschongik/gdsc/domain/member/application/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.gdschongik.gdsc.domain.member.application; | ||
|
||
import com.gdschongik.gdsc.domain.member.dao.MemberRepository; | ||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest; | ||
import com.gdschongik.gdsc.domain.member.dto.response.AdminMemberFindAllResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public Page<AdminMemberFindAllResponse> findAll(MemberQueryRequest queryRequest, Pageable pageable) { | ||
Page<Member> members = memberRepository.findAll(queryRequest, pageable); | ||
return members.map(AdminMemberFindAllResponse::of); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gdschongik/gdsc/domain/member/dao/MemberCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.gdschongik.gdsc.domain.member.dao; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface MemberCustomRepository { | ||
Page<Member> findAll(MemberQueryRequest queryRequest, Pageable pageable); | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/gdschongik/gdsc/domain/member/dao/MemberCustomRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.gdschongik.gdsc.domain.member.dao; | ||
|
||
import static com.gdschongik.gdsc.domain.member.domain.QMember.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest; | ||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.support.PageableExecutionUtils; | ||
|
||
@RequiredArgsConstructor | ||
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)) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
JPAQuery<Long> countQuery = | ||
queryFactory.select(member.count()).from(member).where(queryOption(queryRequest)); | ||
|
||
return PageableExecutionUtils.getPage(fetch, pageable, countQuery::fetchOne); | ||
} | ||
|
||
private BooleanBuilder queryOption(MemberQueryRequest queryRequest) { | ||
BooleanBuilder booleanBuilder = new BooleanBuilder(); | ||
|
||
return booleanBuilder | ||
.and(eqStudentId(queryRequest.studentId())) | ||
.and(eqName(queryRequest.name())) | ||
.and(eqPhone(queryRequest.phone())) | ||
.and(eqDepartment(queryRequest.department())) | ||
.and(eqEmail(queryRequest.email())) | ||
.and(eqDiscordUsername(queryRequest.discordUsername())) | ||
.and(eqDiscordNickname(queryRequest.discordNickname())); | ||
} | ||
|
||
private BooleanExpression eqStudentId(String studentId) { | ||
return studentId != null ? member.studentId.containsIgnoreCase(studentId) : null; | ||
} | ||
|
||
private BooleanExpression eqName(String name) { | ||
return name != null ? member.name.containsIgnoreCase(name) : null; | ||
} | ||
|
||
private BooleanExpression eqPhone(String phone) { | ||
return phone != null ? member.phone.containsIgnoreCase(phone) : null; | ||
} | ||
|
||
private BooleanExpression eqDepartment(String department) { | ||
return department != null ? member.department.containsIgnoreCase(department) : null; | ||
} | ||
|
||
private BooleanExpression eqEmail(String email) { | ||
return email != null ? member.email.containsIgnoreCase(email) : null; | ||
} | ||
|
||
private BooleanExpression eqDiscordUsername(String discordUsername) { | ||
return discordUsername != null ? member.discordUsername.containsIgnoreCase(discordUsername) : null; | ||
} | ||
|
||
private BooleanExpression eqDiscordNickname(String discordNickname) { | ||
return discordNickname != null ? member.nickname.containsIgnoreCase(discordNickname) : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gdschongik/gdsc/domain/member/dto/request/MemberQueryRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.gdschongik.gdsc.domain.member.dto.request; | ||
|
||
public record MemberQueryRequest( | ||
String studentId, | ||
String name, | ||
String phone, | ||
String department, | ||
String email, | ||
String discordUsername, | ||
String discordNickname) {} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/gdschongik/gdsc/domain/member/dto/response/AdminMemberFindAllResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||
package com.gdschongik.gdsc.domain.member.dto.response; | ||||||
|
||||||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||||||
|
||||||
public record AdminMemberFindAllResponse( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Long memberId, | ||||||
String studentId, | ||||||
String name, | ||||||
String phone, | ||||||
String department, | ||||||
String email, | ||||||
String discordUsername, | ||||||
String nickname) { | ||||||
|
||||||
public static AdminMemberFindAllResponse of(Member member) { | ||||||
return new AdminMemberFindAllResponse( | ||||||
member.getId(), | ||||||
member.getStudentId(), | ||||||
member.getName(), | ||||||
member.getPhone(), | ||||||
member.getDepartment(), | ||||||
member.getEmail(), | ||||||
member.getDiscordUsername(), | ||||||
member.getNickname()); | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Transactional(readOnly = true)
클래스 레벨