-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: 문제 상세 정보 조회 시 입출력 예시 반환 추가 #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough문제 상세 응답 DTO에 테스트케이스 목록 필드를 추가하고, 도메인 서비스가 리포지토리에서 테스트케이스를 포함해 문제를 조회하도록 변경했다. Problem 엔티티에 상위 2개 테스트케이스를 반환하는 메서드를 추가했고, 관련 테스트는 새 리포지토리 메서드로 업데이트됐다. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Service as ProblemDomainService
participant Repo as ProblemRepository
participant Entity as Problem
participant DTO as ProblemDetailResponse
Client->>Service: getProblem(problemId)
Service->>Repo: findProblemWithTestcasesById(problemId)
Repo-->>Service: Optional<Problem(with testcases)>
alt Problem found
Service->>Entity: top2Testcases()
Entity-->>Service: List<Testcase>(≤2, sorted by id)
Service->>DTO: from(Problem, mapped TestcaseResponse list)
DTO-->>Service: ProblemDetailResponse
Service-->>Client: ProblemDetailResponse
else Not found
Service-->>Client: throw NotFoundException
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/test/java/org/ezcode/codetest/domain/problem/service/ProblemDomainServiceTest.java (1)
93-94: 리포지토리 메서드 변경 반영 OK
findProblemWithTestcasesById로의 스텁/검증 업데이트가 적절합니다.보완 권장:
- “삭제된 문제는 조회 불가” 케이스를 추가해 soft-delete 필터를 회귀 방지하세요.
예시 테스트 추가(참고):
@Test @DisplayName("삭제된 문제 조회 시 예외") void getProblem_deleted_throws() { Long problemId = 1L; Problem problem = mock(Problem.class); when(problemRepository.findProblemWithTestcasesById(problemId)).thenReturn(Optional.of(problem)); when(problem.getIsDeleted()).thenReturn(true); // 리포지토리가 필터를 보장하지 않는 경우 대비 assertThrows(ProblemException.class, () -> problemDomainService.getProblem(problemId)); }리포지토리가 이미 필터를 보장한다면 위 테스트는 리포지토리 단위 테스트로 이동하거나 서비스에서의 방어 로직을 생략해도 됩니다.
Also applies to: 101-102
src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemDetailResponse.java (2)
54-56: 신규 필드 스키마 명세 추가 및 네이밍 컨벤션 확인API 문서 가독성을 위해
testcases에 스키마 설명을 붙이는 것을 권장합니다. 또한 기존 필드들이 lowerCamelCase를 따르는 만큼,testcasesvstestCases네이밍을 한 번 더 결정해 주세요(신규 필드라 호환성 부담이 낮습니다).스키마 주석 예시(간단):
- String imageUrl, - - List<TestcaseResponse> testcases + String imageUrl, + + @Schema(description = "입출력 예시(최대 2건)") + List<TestcaseResponse> testcases
75-76: LazyInitializationException 위험 없음:ProblemDetailResponse.from은@Transactional(readOnly=true)이 적용된ProblemService.getProblem내에서 호출되며,ProblemDomainService.getProblem의 fetch-join으로 테스트케이스가 이미 로드됩니다.
- (권장) 상세 화면에 상위 2건만 필요하다면
TestcaseRepository.findTop2ByProblemIdOrderByIdAsc같은 별도 쿼리로 I/O를 최적화하세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemDetailResponse.java(2 hunks)src/main/java/org/ezcode/codetest/application/problem/dto/response/TestcaseResponse.java(0 hunks)src/main/java/org/ezcode/codetest/domain/problem/model/entity/Problem.java(2 hunks)src/main/java/org/ezcode/codetest/domain/problem/service/ProblemDomainService.java(1 hunks)src/test/java/org/ezcode/codetest/domain/problem/service/ProblemDomainServiceTest.java(1 hunks)
💤 Files with no reviewable changes (1)
- src/main/java/org/ezcode/codetest/application/problem/dto/response/TestcaseResponse.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-02T12:05:54.917Z
Learnt from: Kimminu7
PR: ezcode-my/backend#133
File: src/test/java/org/ezcode/codetest/domain/problem/service/ProblemDomainServiceTest.java:92-99
Timestamp: 2025-07-02T12:05:54.917Z
Learning: ProblemDomainService의 removeProblem 메서드는 DB에서 Problem을 삭제한 후 Elasticsearch에서도 해당 ProblemSearchDocument를 찾아서 삭제합니다. 만약 Elasticsearch에서 문서를 찾지 못하면 ProblemException(PROBLEM_NOT_FOUND)을 던지므로, 테스트에서는 problem.getId()와 searchRepository.findById() 모두 적절하게 mock해야 합니다.
Applied to files:
src/main/java/org/ezcode/codetest/domain/problem/service/ProblemDomainService.javasrc/test/java/org/ezcode/codetest/domain/problem/service/ProblemDomainServiceTest.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
src/main/java/org/ezcode/codetest/domain/problem/model/entity/Problem.java (1)
4-4: top2Testcases 성능 및 NPE 안전성 선택적 개선 제안
- 대규모
testcases리스트에서 매 호출 O(n log n) 정렬 비용이 부담된다면,
@onetomany 필드에
@OrderBy("id ASC")
를 추가한 뒤
return testcases.isEmpty() ? List.of() : List.copyOf(testcases.subList(0, Math.min(2, testcases.size())));
로 슬라이싱해 O(n)으로 개선할 수 있습니다.Testcase.id는@GeneratedValue(strategy = GenerationType.IDENTITY)적용 시 영속화 후 non-null이 보장되므로 NPE 우려는 사실상 없습니다.
– 영속화 전 호출할 가능성이 있다면,
.sorted(Comparator.comparing(Testcase::getId, Comparator.nullsLast(Comparator.naturalOrder())))
처럼 null-safe 정렬을 선택하세요.
| return problemRepository.findProblemWithTestcasesById(problemId) | ||
| .orElseThrow(() -> new ProblemException(ProblemExceptionCode.PROBLEM_NOT_FOUND)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
findProblemWithTestcasesById가 soft-delete 필터를 포함하는지 확인 필요
기존 findByIdNotDeleted에서 전환되며 삭제된 문제 노출 위험이 생길 수 있습니다. 리포지토리 쿼리에 isDeleted = false 조건과 테스트케이스 fetch-join이 포함되는지 확인해 주세요. 미보장 시, 리포지토리 수정 또는 방어적 체크 추가가 필요합니다.
검증 스크립트:
추가 제안(옵션):
- 본 메서드가 다양한 호출처에서 사용된다면, 안전망으로 조회 후
problem.getIsDeleted()체크를 넣는 것도 고려해 주세요. - 읽기 전용 쿼리 메서드(
getProblem,getProblemInfo)에@Transactional(readOnly = true)부여를 검토하면 LAZY 초기화/성능 측면에서 안전합니다.
🏁 Script executed:
#!/bin/bash
# ProblemRepository 에서 쿼리와 soft-delete 필터 확인
rg -nP --type java -C3 '\binterface\s+ProblemRepository\b'
rg -nP --type java -C6 '\bfindProblemWithTestcasesById\s*\('
# 쿼리 본문/스펙 내 isDeleted 필터 존재 여부 확인
rg -nP --type java -C3 'findProblemWithTestcasesById|isDeleted|fetch\s+join'Length of output: 57295
ProblemJpaRepository.findProblemWithTestcasesById에 soft-delete 필터(isDeleted = false) 추가
현재 JPA 쿼리에 p.isDeleted = false 조건이 빠져 있어 삭제된(soft-deleted) 문제도 조회될 수 있습니다. where p.isDeleted = false and p.id = :problemId로 쿼리를 수정하거나, 서비스 계층에서 조회 후 problem.getIsDeleted() 방어적 체크를 추가해 주세요.
🤖 Prompt for AI Agents
In
src/main/java/org/ezcode/codetest/domain/problem/service/ProblemDomainService.java
around lines 100 to 102, the repository call returns soft-deleted entities
because the JPA query lacks a p.isDeleted = false filter; update the repository
method findProblemWithTestcasesById to include where p.isDeleted = false and
p.id = :problemId so deleted problems are never returned, or if you cannot
change the repository right now, add a defensive check after retrieval to throw
ProblemException(ProblemExceptionCode.PROBLEM_NOT_FOUND) when
problem.getIsDeleted() == true; ensure only non-deleted problems are treated as
found.
Summary by CodeRabbit