Skip to content

bug: 사용자 목록·발급이력 페이지네이션에 안정 정렬 키 추가 (#65) - #73

Merged
cowtree28 merged 2 commits into
developfrom
bug/65-user-list-sort
Oct 6, 2026
Merged

cowtree28 merged 2 commits into
developfrom
bug/65-user-list-sort

Conversation

@cowtree28

Copy link
Copy Markdown
Contributor

개요

목록 조회 두 곳에 안정 정렬(stable sort) 키가 없어서 페이지를 넘길 때 같은 행이 두 번 나오거나 아예 누락될 수 있었다.

  • GET /api/admins (사용자 목록): Pageable에 Sort가 아예 없었다. 정렬이 없으면 DB가 행 순서를 보장하지 않으므로 페이지마다 순서가 달라지고, 경계에 걸친 행이 중복/누락된다.
  • GET /api/issuance-histories (발급 이력): order by i.issuedAt desc만 있어 동일 issuedAt 동점 처리가 없었다. 같은 초에 여러 건이 발급되면 같은 문제가 생긴다.

human/search는 이미 Sort.by("humanId")로 막아두고 주석까지 달려 있었다. 같은 방어를 나머지 두 곳에 맞췄다.

Closes #65

변경 내용

  • admin/service/QueryUserListService
    • PageNumber.toPageable(page, size, Sort.by(ASC, "id"))로 정렬 키를 넣었다.
    • 정렬 프로퍼티를 **Admin.id**로 잡았다. Admin은 @MapsId로 user_id를 PK로 쓰므로 id가 곧 사용자 ID이고 유일하다. admin 테이블 자체 컬럼이라 User로 조인을 타지 않는다. user.name은 동명이인에서 다시 불안정해져 2차 키 없이는 쓸 수 없으므로 쓰지 않았다.
  • certificate/repository/CertificateIssuedRepository.searchHistories
    • order by i.issuedAt desc → order by i.issuedAt desc, i.certificateIssuedId desc. 1차 정렬(발급 최신순)은 그대로고, 동점일 때만 유일 키로 순서를 확정한다.
  • human/search는 손대지 않았다.

테스트

전체 88개 전부 통과 (기존 80 + 추가 8).

추가한 테스트 8개:

  • admin/UserListPagingApiTest (3) — MockMvc 통합
    • size보다 많은 데이터(7건, size 3)를 만들고 1·2페이지를 받아 식별자 집합이 겹치지 않는지 확인
    • 모든 페이지를 순회해 합집합이 전체 7건과 정확히 일치하고 중복이 없는지 확인
    • 같은 페이지를 두 번 불러도 같은 순서인지 + 오름차순인지 확인 (정렬 프로퍼티 경로가 JPA에서 유효하다는 것도 여기서 검증된다 — 잘못된 경로는 런타임에만 터지므로)
  • admin/service/QueryUserListServiceTest (2) — Mockito
    • Pageable을 캡처해 정렬이 실제로 실려 나가는지 단언. H2/Postgres가 우연히 삽입 순서를 돌려주면 통합 테스트만으로는 정렬 누락이 안 잡히기 때문에 둔 가드다 (정렬을 되돌리면 이 둘이 바로 깨지는 것을 확인했다).
    • 페이지 번호 1-base → 0-index 변환이 유지되는지도 같이 확인
  • domain/certificate/IssuanceHistoryPagingApiTest (3) — MockMvc 통합
    • issuedAt이 전부 동일한 발급 7건을 만들어 1·2페이지 중복 없음 / 전체 합집합 일치 검증
    • 동점 시 certificateIssuedId 내림차순으로 안정 정렬되는지 검증 (2차 정렬 키를 빼면 이 테스트가 깨지는 것을 확인했다)

FE / 리뷰어가 알아야 할 것

  • FE 변경 없음. 응답 형식(PageResponse 봉투, 필드명, 상태 코드)은 그대로다. 바뀐 것은 행의 순서뿐이다.
    • GET /api/admins: 기존에는 순서가 비결정적이었고, 이제 사용자 ID 오름차순으로 고정된다.
    • GET /api/issuance-histories: 발급 최신순은 그대로이고, 같은 시각 동점일 때만 발급 ID 내림차순(= 나중에 저장된 건이 먼저)으로 고정된다.
  • 마이그레이션 / 스키마 변경 없음. 엔티티·컬럼을 건드리지 않았으므로 schema.sql 변경도 없다.
  • 미해결 결정사항: 사용자 목록의 정렬 기준을 ID 오름차순으로 뒀다. 화면에서 "이름 가나다순"이 필요하다면 Sort.by("user.name").and(Sort.by("id"))처럼 2차 키를 붙여 바꿀 수 있다(조인이 필요해 @EntityGraph와의 조합을 확인해야 한다). 이번 PR 범위는 "불안정한 페이지네이션 수정"이라 UX 정렬 기준 변경은 하지 않았다.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ed77ea20-7d8c-45c9-93f9-407717901111
📥 Commits

Reviewing files that changed from the base of the PR and between c5d7f2e and f261af0.

📒 Files selected for processing (5)
  • src/main/java/commonly/commonlybe/admin/service/QueryUserListService.java
  • src/main/java/commonly/commonlybe/certificate/repository/CertificateIssuedRepository.java
  • src/test/java/commonly/commonlybe/admin/UserListPagingApiTest.java
  • src/test/java/commonly/commonlybe/admin/service/QueryUserListServiceTest.java
  • src/test/java/commonly/commonlybe/domain/certificate/IssuanceHistoryPagingApiTest.java
 ______________________________________________________________________________________________________________________________________________________________
< Find bugs once. Once a human tester finds a bug, it should be the last time a human tester finds that bug. Automatic tests should check for it from then on. >
 --------------------------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cowtree28
cowtree28 merged commit f646f5f into develop Oct 6, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

사용자 목록 조회에 정렬이 없어 페이지가 불안정하다

1 participant