Skip to content

Commit

Permalink
어드민 : 회원 조회 -> 기수 > 대학 > 역할 > 이름 정렬 (#90)
Browse files Browse the repository at this point in the history
* feat : 본사 회원 조회 api

* feat : 본사 회원 조회 api

* refact : 회원 삭제

* refact : 회원 역할 수정

* refact : 본사에 의한 회원 조회 및 역할 수정

* refact : 본사에 의한 회원 조회

* refact : 역할 수정 에러 해결

* refact : 페이지당 요소 출력

* refact : 페이지당 요소 출력

* fix : ids::size 적용

* fix : ids::size 적용

* fix : 기수, 대학, 역할, 이름 순으로 정렬

* fix : 기수, 대학, 역할, 이름 순으로 정렬

* fix : 기수, 대학, 파트, 이름 순으로 정렬

* refact : 학교대표 어드민 정렬
  • Loading branch information
songhyeon99 authored Jan 31, 2024
1 parent d30b702 commit c225407
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface UserCustomRepository {
List<User> findMyFollowingUsersByFollowingIdIn(Long followerId, List<Long> followingIdList);
Page<User> findAllWithUniversity(Pageable pageable);
Page<User> findByUnivNameAndRole(Role role, String univName, Pageable pageable);
Page<User> findByUniversityInfoUniversityId(Long univId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
public interface UserRepository extends JpaRepository<User,Long>, UserCustomRepository {
Optional<User> findByAuthInfoEmail(String email);
Boolean existsByAuthInfoEmail(String email);
@Query(value = "SELECT u FROM User u join fetch u.universityInfo.university " +
"where u.universityInfo.university.id = :univId and u.authInfo.accountStatus= 'ACTIVE' ",
countQuery = "SELECT count(u.id) FROM User u join u.universityInfo.university " +
"where u.universityInfo.university.id = :univId and u.authInfo.accountStatus= 'ACTIVE'")
Page<User> findByUniversityInfoUniversityId(Long univId, Pageable pageable);

@Query(value = "SELECT u FROM User u join fetch u.universityInfo.university where u.id = :id ")
Optional<User> findByIdWithUniversity(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ private BooleanExpression eqPart(String searchPart) {
return searchPart != null ? user.profile.part.eq(Part.valueOf(searchPart)) : null;
}

private BooleanExpression eqUnivId(Long univId) {
return univId != null ? user.universityInfo.university.id.eq(univId) : null;
}

private BooleanExpression eqRole(Role role) {
return role != null ?
switch (role){
Expand All @@ -72,10 +76,44 @@ private BooleanExpression eqRole(Role role) {
: null;
}

@Override
public Page<User> findByUniversityInfoUniversityId(Long univId, Pageable pageable){
List<Long> ids = getCoveringIndex(null);
NumberExpression<Integer> partOrder = new CaseBuilder()
.when(user.profile.part.eq(Part.PM)).then(1)
.when(user.profile.part.eq(Part.DESIGNER)).then(2)
.when(user.profile.part.eq(Part.PM_DESIGNER)).then(3)
.when(user.profile.part.eq(Part.FRONTEND)).then(4)
.when(user.profile.part.eq(Part.BACKEND)).then(5)
.otherwise(6);
List<User> users =
queryFactory
.select(user)
.from(user)
.innerJoin(user.universityInfo.university, university).fetchJoin()
.where( eqUnivId(univId),
user.id.in(ids))
.offset(pageable.getOffset())
.orderBy(user.universityInfo.ordinal.desc(),
user.universityInfo.university.name.asc(),
partOrder.asc(),
user.profile.name.asc())
.limit(pageable.getPageSize())
.fetch();

return PageableExecutionUtils.getPage(users, pageable, ids::size);
}

@Override
public Page<User> findByUnivNameAndRole(Role role, String univName, Pageable pageable){
List<Long> ids = getCoveringIndex(null);
NumberExpression<Integer> partOrder = new CaseBuilder()
.when(user.profile.part.eq(Part.PM)).then(1)
.when(user.profile.part.eq(Part.DESIGNER)).then(2)
.when(user.profile.part.eq(Part.PM_DESIGNER)).then(3)
.when(user.profile.part.eq(Part.FRONTEND)).then(4)
.when(user.profile.part.eq(Part.BACKEND)).then(5)
.otherwise(6);
List<User> users =
queryFactory
.select(user)
Expand All @@ -85,7 +123,10 @@ public Page<User> findByUnivNameAndRole(Role role, String univName, Pageable pag
eqRole(role),
user.id.in(ids))
.offset(pageable.getOffset())
.orderBy(user.createdDate.desc())
.orderBy(user.universityInfo.ordinal.desc(),
user.universityInfo.university.name.asc(),
partOrder.asc(),
user.profile.name.asc())
.limit(pageable.getPageSize())
.fetch();

Expand Down

0 comments on commit c225407

Please sign in to comment.