Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ public class UserAdminController {
@GetMapping
public ResponseEntity<ApiResponse<Page<UserSummaryResponse>, PageMeta>> list(
@RequestParam(required = false) String q,
@RequestParam(required = false) UserRole role,
@RequestParam(required = false) TeamType team,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int size,
@RequestParam(defaultValue = "name") String sort,
@RequestParam(defaultValue = "ASC") String dir
) {
Sort.Direction direction = "ASC".equalsIgnoreCase(dir) ? Sort.Direction.ASC : Sort.Direction.DESC;
Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sort));

Page<UserSummaryResponse> result = userAdminService.listUsers(q, role, team, pageable);
Page<UserSummaryResponse> result = userAdminService.listUsers(q, pageable);
return ResponseEntity.ok(ApiResponse.ok("USER_SUMMARY_LIST_RETRIEVED", result, PageMeta.of(result)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public interface UserRepository extends JpaRepository<User, Long>, UserRepositoryCustom {

boolean existsByNameAndEmail(String name, String email);

boolean existsByEmail(String email);

/* ===== 출석/팀 뷰용 기본 쿼리 ===== */
Expand All @@ -38,22 +37,13 @@ public interface UserRepository extends JpaRepository<User, Long>, UserRepositor
List<User> findByTeam(TeamType team);

@Query("""
select new inha.gdgoc.domain.user.dto.response.UserSummaryResponse(
u.id, u.name, u.major, u.studentId, u.email, u.userRole, u.team
)
from User u
where
(
:q is null or :q = '' or
lower(u.name) like lower(concat('%', :q, '%')) or
lower(u.email) like lower(concat('%', :q, '%')) or
u.studentId like concat('%', :q, '%') or
lower(u.major) like lower(concat('%', :q, '%'))
)
and (:role is null or u.userRole = :role)
and (:team is null or u.team = :team)
""")
Page<UserSummaryResponse> findSummaries(@Param("q") String q, @Param("role") inha.gdgoc.domain.user.enums.UserRole role, @Param("team") inha.gdgoc.domain.user.enums.TeamType team, Pageable pageable);
select new inha.gdgoc.domain.user.dto.response.UserSummaryResponse(
u.id, u.name, u.major, u.studentId, u.email, u.userRole, u.team
)
from User u
where (:q is null or :q = '' or u.name like concat('%', :q, '%'))
""")
Page<UserSummaryResponse> findSummaries(@Param("q") String q, Pageable pageable);

@NotNull Optional<User> findById(@NotNull Long id);
}
16 changes: 11 additions & 5 deletions src/main/java/inha/gdgoc/domain/user/service/UserAdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public class UserAdminService {
/* ======================= 목록 ======================= */

@Transactional(readOnly = true)
public Page<UserSummaryResponse> listUsers(String q, UserRole role, TeamType team, Pageable pageable) {
public Page<UserSummaryResponse> listUsers(String q, Pageable pageable) {
Pageable fixed = rewriteSort(pageable);
// 레포지토리에 role/team 조건 추가한 메서드가 있어야 함
return userRepository.findSummaries(q, role, team, fixed);
return userRepository.findSummaries(q, fixed);
}

private Pageable rewriteSort(Pageable pageable) {
Expand All @@ -48,14 +47,21 @@ private Pageable rewriteSort(Pageable pageable) {

if ("userRole".equals(prop)) {
hasUserRoleOrder = true;
String roleRankCase = "CASE u.userRole " + "WHEN 'GUEST' THEN 0 " + "WHEN 'MEMBER' THEN 1 " + "WHEN 'CORE' THEN 2 " + "WHEN 'LEAD' THEN 3 " + "WHEN 'ORGANIZER' THEN 4 " + "WHEN 'ADMIN' THEN 5 " + "ELSE -1 END";
String roleRankCase =
"(CASE " +
" WHEN u.userRole = 'GUEST' THEN 0 " +
" WHEN u.userRole = 'MEMBER' THEN 1 " +
" WHEN u.userRole = 'CORE' THEN 2 " +
" WHEN u.userRole = 'LEAD' THEN 3 " +
" WHEN u.userRole = 'ORGANIZER' THEN 4 " +
" WHEN u.userRole = 'ADMIN' THEN 5 " +
" ELSE -1 END)";
composed = composed.and(JpaSort.unsafe(dir, roleRankCase));
} else {
composed = composed.and(Sort.by(new Sort.Order(dir, prop)));
}
}

// ROLE 정렬이 있으면 같은 권한 내 name ASC로 안정화
if (hasUserRoleOrder) {
composed = composed.and(Sort.by("name").ascending());
}
Expand Down
Loading