Skip to content

Commit b4e4b6f

Browse files
committed
♻️ refactor: 정렬 조건 변경
1 parent 0ff3fe1 commit b4e4b6f

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

backend/src/main/java/io/f1/backend/domain/admin/api/AdminController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public class AdminController {
2323

2424
@LimitPageSize
2525
@GetMapping("/users")
26-
public ResponseEntity<UserPageResponse> getUsers(
27-
@PageableDefault(sort = "lastLogin", direction = Direction.DESC) Pageable pageable) {
26+
public ResponseEntity<UserPageResponse> getUsers(Pageable pageable) {
2827
UserPageResponse response = adminService.getAllUsers(pageable);
2928
return ResponseEntity.ok().body(response);
3029
}

backend/src/main/java/io/f1/backend/domain/user/dao/UserRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
2020

2121
@Query(
2222
"SELECT new io.f1.backend.domain.admin.dto.UserResponse(u.id, u.nickname, u.lastLogin,"
23-
+ " u.createdAt)FROM User u ORDER BY u.lastLogin DESC")
23+
+ " u.createdAt)FROM User u ORDER BY u.id")
2424
Page<UserResponse> findAllUsersWithPaging(Pageable pageable);
2525
}

backend/src/test/java/io/f1/backend/domain/admin/app/AdminServiceTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void totalUser() throws Exception {
3434

3535
@Test
3636
@DataSet("datasets/admin/sorted-user.yml")
37-
@DisplayName("유저 목록이 최근 로그인 순(내림차순)으로 정렬되어 반환된다")
37+
@DisplayName("유저 목록이 id 순으로 정렬되어 반환된다")
3838
void getUsersSortedByLastLogin() throws Exception {
3939
// when
4040
ResultActions result = mockMvc.perform(get("/admin/users"));
@@ -43,10 +43,10 @@ void getUsersSortedByLastLogin() throws Exception {
4343
status().isOk(),
4444
jsonPath("$.totalElements").value(3),
4545
// 가장 최근 로그인한 USER3이 첫 번째
46-
jsonPath("$.users[0].nickname").value("USER3"),
46+
jsonPath("$.users[0].id").value(1),
4747
// 중간 로그인한 USER2가 두 번째
48-
jsonPath("$.users[1].nickname").value("USER2"),
48+
jsonPath("$.users[1].id").value(2),
4949
// 가장 오래된 로그인한 USER1이 세 번째
50-
jsonPath("$.users[2].nickname").value("USER1"));
50+
jsonPath("$.users[2].id").value(3));
5151
}
5252
}

0 commit comments

Comments
 (0)