Skip to content

[Fix/#268] 기수 정렬을 alias로 해결할 수 없는 문제 수정 - #269

Merged
sung-silver merged 4 commits into
devfrom
fix/#268
Apr 13, 2026
Merged

[Fix/#268] 기수 정렬을 alias로 해결할 수 없는 문제 수정#269
sung-silver merged 4 commits into
devfrom
fix/#268

Conversation

@sung-silver

Copy link
Copy Markdown
Contributor

Related Issue 🚀

Work Description ✏️

  • alias 문제 수정

PR Point 📸

@sung-silver sung-silver self-assigned this Apr 13, 2026
@sung-silver sung-silver added the 🔨 fix 버그를 발견하여 코드를 수정한 경우(spring boot 내의 기능 코드) label Apr 13, 2026
@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@sung-silver has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 19 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 0 minutes and 19 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f3e23e26-607c-4db7-bb14-83b80936b255

📥 Commits

Reviewing files that changed from the base of the PR and between f9f0cda and 3dee2fd.

📒 Files selected for processing (1)
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java

Walkthrough

User 조회에 UserOrderBy 기반 생성 연도 정렬 경로가 추가되어, 생성 연도 기준으로 정렬된 사용자 ID 페이징을 반환하는 JPA 메서드 2개가 추가되고 이를 이용해 정렬된 Page를 구성하도록 검색 로직이 변경됨.

Changes

Cohort / File(s) Summary
JPA 리포지토리 쿼리 추가
src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserJpaRepository.java
활동 이력과 조인해 사용자 ID만 반환하는 페이징 메서드 2개 추가: findUserIdsOrderByMatchedGenerationDesc, findUserIdsOrderByMatchedGenerationAsc (동일한 필터 적용, generation DESC/ASC).
검색/조회 계층 변경
src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java, src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRepositoryImpl.java, src/main/java/sopt/makers/authentication/application/port/out/user/UserRepository.java
API/리포지토리 시그니처에 UserOrderBy orderBy 인자 추가. orderBy가 generation 계열일 때는 ID 기반 정렬 경로로 분기하여 ID 페이징 결과로부터 엔티티를 재조회하고 요청한 순서로 Page를 구성하도록 로직 추가(부재시 예외 처리 포함).
서비스 레이어 조정
src/main/java/sopt/makers/authentication/application/service/user/GetUserProfileService.java
USER_ACTIVITY_SORT_ALIAS 제거 및 orderBy 전달 추가. generation 정렬 시 기존의 커스텀 Sort 지정 제거하고 PageRequest만 생성하도록 pageable 처리 변경.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Service as GetUserProfileService
    participant RepoAPI as UserRepository (port)
    participant Retriever as UserRetriever
    participant JPA as UserJpaRepository
    participant DB

    Client->>Service: 요청(filters, pageable, orderBy)
    Service->>RepoAPI: findAllByGenerationAndPartAndNameAndTeam(..., pageable, orderBy)
    RepoAPI->>Retriever: findAllByGenerationAndPartAndNameAndTeam(..., pageable, orderBy)
    alt orderBy.isGenerationOrder()
        Retriever->>JPA: findUserIdsOrderByMatchedGenerationDesc/Asc(filters, pageable)
        JPA->>DB: 실행 (JOIN userActivityHistory, GROUP BY u.id, ORDER BY matched generation)
        DB-->>JPA: Page<Long> (ordered userIds)
        Retriever->>JPA: findAllByIdIn(orderedIds)
        JPA->>DB: 조회 UserEntity by ids
        DB-->>JPA: List<UserEntity>
        Retriever-->>RepoAPI: Page<User> (constructed preserving id order)
    else
        Retriever->>JPA: 기존 UserEntity 기반 페이징 쿼리(filters, pageable)
        JPA->>DB: 실행
        DB-->>JPA: Page<UserEntity>
        Retriever-->>RepoAPI: Page<User> (mapped from entities)
    end
    RepoAPI-->>Service: Page<User>
    Service-->>Client: 결과 반환
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 당근 대신 쿼리를 쥐고,
세대 순서로 줄을 세웠네,
아이디 먼저 뽑아 다시 부르면,
질서 정연히 사용자들이 줄 서요,
후다닥 검색, 토끼가 기뻐 웃네.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR 설명은 템플릿 구조를 따르고 있으나, 'Work Description'에 매우 간단한 설명('alias 문제 수정')만 있고 구체적인 기술적 내용이나 리뷰 포인트가 부족합니다. Work Description을 더 구체적으로 작성하여 쿼리 구조 변경, 새로운 메서드 추가, UnknownPathException 해결 방식 등을 설명해주세요.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 linked issue #268의 검색 API 500 에러 수정과 관련된 기수 정렬 alias 문제를 명확하게 반영하고 있으며, 변경 내용과 일치합니다.
Linked Issues check ✅ Passed 코드 변경사항이 linked issue #268의 UnknownPathException 문제를 직접 해결합니다. 새로운 JPA 메서드로 올바른 쿼리를 제공하고, UserRetriever에서 생성된 ID 목록을 사용하여 엔티티를 로드함으로써 잘못된 alias 참조를 제거했습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 linked issue #268의 검색 API 500 에러 해결과 관련된 범위 내에 있으며, 추가 기능이나 무관한 수정은 없습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/#268

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserJpaRepository.java`:
- Around line 59-99: The current queries in
findAllWithActivityHistoriesOrderByGenerationDesc and
findAllWithActivityHistoriesOrderByGenerationAsc use JOIN FETCH
u.userActivityHistoryList (alias ah) for ordering but apply filters against a
different alias a, so ordering can come from unrelated histories and paging is
unstable; change to a two-step approach: (1) add new repository methods (or
modify these) to first select only UserEntity ids using a grouped query on
UserActivityHistoryEntity (alias a) applying the
generation/part/team/isAdmin/name filters and ordering by MAX(a.generation) for
DESC (MIN(a.generation) for ASC) with Pageable to get the page of ids, and (2)
reuse the existing findAllWithActivityHistoriesByIdIn to fetch full UserEntity
objects and their userActivityHistoryList for the returned ids in a second
query; ensure method names referenced are
findAllWithActivityHistoriesOrderByGenerationDesc/findAllWithActivityHistoriesOrderByGenerationAsc
and findAllWithActivityHistoriesByIdIn so callers can be updated to perform the
two-step fetch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c8c874e-d361-4bc4-b667-29cda8bcdc07

📥 Commits

Reviewing files that changed from the base of the PR and between 788153f and a644949.

📒 Files selected for processing (5)
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserJpaRepository.java
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRepositoryImpl.java
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java
  • src/main/java/sopt/makers/authentication/application/port/out/user/UserRepository.java
  • src/main/java/sopt/makers/authentication/application/service/user/GetUserProfileService.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java`:
- Around line 104-115: The current code silently drops IDs missing from the
second query (userJpaRepository.findAllWithActivityHistoriesByIdIn) which can
make PageImpl(content, pageable, userIdPage.getTotalElements()) inconsistent;
after building userById from that repository call, detect if any orderedIds are
missing (compare orderedIds against userById.keySet()) and fail fast by throwing
an IllegalStateException (or custom exception) that includes the missing ID list
and context (e.g., mentioning orderedIds, userById, and
userIdPage.getTotalElements()); only convert to domain (UserEntity::toDomain)
and construct PageImpl if no IDs are missing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90a835bd-0f59-46b0-ba89-60a12124b021

📥 Commits

Reviewing files that changed from the base of the PR and between a644949 and 70cd334.

📒 Files selected for processing (2)
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserJpaRepository.java
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserJpaRepository.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java (1)

98-100: 빈 페이지 처리 방식 개선을 권장합니다.

userIdPage.map(id -> null) 코드는 동작하지만, null을 반환하는 람다는 의미적으로 혼란스럽습니다. 더 명시적인 방식으로 빈 페이지를 생성하는 것이 가독성에 좋습니다.

♻️ 제안 수정안
     List<Long> orderedIds = userIdPage.getContent();
     if (orderedIds.isEmpty()) {
-      return userIdPage.map(id -> null);
+      return new PageImpl<>(List.of(), pageable, userIdPage.getTotalElements());
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java`
around lines 98 - 100, In UserRetriever, replace the confusing userIdPage.map(id
-> null) when orderedIds.isEmpty() with an explicit empty Page return; for
example return Page.empty(userIdPage.getPageable()) (or, if your Spring version
lacks that helper, return new PageImpl<>(Collections.emptyList(),
userIdPage.getPageable(), 0)) so the intent is clear and you avoid mapping to
nulls.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java`:
- Around line 98-100: In UserRetriever, replace the confusing userIdPage.map(id
-> null) when orderedIds.isEmpty() with an explicit empty Page return; for
example return Page.empty(userIdPage.getPageable()) (or, if your Spring version
lacks that helper, return new PageImpl<>(Collections.emptyList(),
userIdPage.getPageable(), 0)) so the intent is clear and you avoid mapping to
nulls.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 400275a7-58a0-4faa-b5f7-ff147fc38c4d

📥 Commits

Reviewing files that changed from the base of the PR and between 70cd334 and f9f0cda.

📒 Files selected for processing (1)
  • src/main/java/sopt/makers/authentication/adapter/out/persistence/repository/user/UserRetriever.java

@sung-silver
sung-silver merged commit c3e3413 into dev Apr 13, 2026
2 checks passed
@sung-silver
sung-silver deleted the fix/#268 branch April 13, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 fix 버그를 발견하여 코드를 수정한 경우(spring boot 내의 기능 코드)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] search api 500 에러 수정

1 participant