-
Notifications
You must be signed in to change notification settings - Fork 3
refactor : 문제 이미지만 수정 로직, UI 부분 추가 #156
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문제 이미지 URL을 응답 DTO에 추가하고, 기존 문제에 이미지를 추가하는 서비스 메서드와 관리자 전용 이미지 수정 엔드포인트를 신설했습니다. 또한, 문제 상세 HTML에 이미지 표시 영역을 추가하고, JS에서 동적으로 이미지를 표시하도록 수정했습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Admin as 관리자(ADMIN)
participant Controller as ProblemAdminController
participant Service as ProblemService
participant S3 as S3 저장소
participant DB as DB
Admin->>Controller: PUT /image/{problemId} (이미지 파일)
Controller->>Service: addImageToExistingProblem(problemId, imageFile)
Service->>DB: 문제 조회 (problemId)
Service->>S3: 이미지 업로드
S3-->>Service: S3 Key 반환
Service->>DB: 문제 엔티티에 이미지 추가 후 저장
Controller-->>Admin: 204 No Content
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
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 (1)
src/main/java/org/ezcode/codetest/presentation/problemmanagement/problem/ProblemAdminController.java (1)
66-76: API 문서와 구현 간 불일치 수정새로운 이미지 수정 엔드포인트에 몇 가지 불일치가 있습니다:
- 응답 코드 불일치:
@ApiResponse에서는 200을 명시하지만 실제로는 204를 반환- 메서드 설명 개선: "문제 이미지 수정"이라고 했지만 서비스 메서드명은 "add"를 사용
다음과 같이 수정하는 것을 제안합니다:
@PutMapping("/image/{problemId}") @Operation(summary = "문제 이미지 수정", description = "문제 이미지 수정합니다.") @PreAuthorize("hasRole('ADMIN')") -@ApiResponse(responseCode = "200", description = "문제 수정 성공") +@ApiResponse(responseCode = "204", description = "문제 이미지 수정 성공") public ResponseEntity<Void> updateProblemImage(
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemDetailResponse.java(2 hunks)src/main/java/org/ezcode/codetest/application/problem/service/ProblemService.java(1 hunks)src/main/java/org/ezcode/codetest/presentation/problemmanagement/problem/ProblemAdminController.java(3 hunks)src/main/resources/templates/test-submit.html(3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: chat26666
PR: ezcode-my/backend#37
File: src/main/java/org/ezcode/codetest/infrastructure/elasticsearch/repository/ProblemElasticsearchRepositoryDsl.java:10-10
Timestamp: 2025-06-06T19:56:27.759Z
Learning: When user chat26666 mentions that code was implemented in a previous PR but explanation was missing, they may submit a follow-up PR just to add documentation/explanation without the actual implementation code.
Learnt from: thezz9
PR: ezcode-my/backend#114
File: src/main/java/org/ezcode/codetest/infrastructure/github/GitHubApiClient.java:159-165
Timestamp: 2025-06-28T02:03:38.693Z
Learning: User thezz9's service (ezcode) targets Korean users exclusively ("찐 한국인밖에 안 옴"), so Korean language hardcoding in commit messages and UI elements is intentional and appropriate for their use case.
src/main/java/org/ezcode/codetest/presentation/problemmanagement/problem/ProblemAdminController.java (2)
Learnt from: NCookies
PR: ezcode-my/backend#17
File: src/main/java/org/ezcode/codetest/presentation/problemmanagement/ProblemAdminController.java:25-25
Timestamp: 2025-06-02T06:57:37.929Z
Learning: 이 프로젝트에서는 아직 Spring Security가 적용되지 않아서 @PreAuthorize 어노테이션이 주석 처리되어 있음. Spring Security 도입 전까지는 권한 검증 어노테이션들이 비활성화 상태임.
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.895Z
Learning: ProblemDomainService의 removeProblem 메서드는 DB에서 Problem을 삭제한 후 Elasticsearch에서도 해당 ProblemSearchDocument를 찾아서 삭제합니다. 만약 Elasticsearch에서 문서를 찾지 못하면 ProblemException(PROBLEM_NOT_FOUND)을 던지므로, 테스트에서는 problem.getId()와 searchRepository.findById() 모두 적절하게 mock해야 합니다.
src/main/java/org/ezcode/codetest/application/problem/service/ProblemService.java (1)
Learnt from: chat26666
PR: ezcode-my/backend#31
File: src/main/java/org/ezcode/codetest/domain/problem/service/ProblemDomainService.java:25-27
Timestamp: 2025-06-04T15:11:19.343Z
Learning: In ProblemDomainService, when saving problems to both database and Elasticsearch, maintain transactional consistency by allowing rollback if either save operation fails. Data integrity between DB and ES is prioritized over availability - if Elasticsearch save fails, the entire transaction should roll back to prevent data inconsistency.
src/main/resources/templates/test-submit.html (1)
Learnt from: thezz9
PR: ezcode-my/backend#73
File: src/main/resources/templates/submit-test.html:135-135
Timestamp: 2025-06-18T11:41:58.457Z
Learning: src/main/resources/templates/submit-test.html 파일은 테스트용 파일로, isCorrect 값의 하드코딩은 의도적이며 사용자가 UI 요소를 통해 정답/오답 상태를 선택할 수 있도록 개선 예정입니다.
🪛 HTMLHint (1.5.0)
src/main/resources/templates/test-submit.html
[error] 290-290: The attribute [ src ] of the tag [ img ] must have a value.
(src-not-empty)
⏰ 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 (5)
src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemDetailResponse.java (2)
53-54: 이미지 URL 필드 추가 승인새로운
imageUrl필드가 적절히 추가되었습니다. Swagger 문서화도 잘 되어 있습니다.
73-73: 이미지 URL 매핑 로직 승인첫 번째 이미지 URL을 가져오는 로직이 올바르게 구현되었습니다. 빈 리스트에 대한 null 처리도 적절합니다.
src/main/resources/templates/test-submit.html (3)
289-291: 이미지 표시 영역 추가 승인문제 이미지를 표시하기 위한 HTML 요소가 적절히 추가되었습니다. 반응형 스타일링도 잘 적용되어 있습니다.
341-341: 이미지 요소 참조 변수 추가 승인JavaScript에서 이미지 요소를 참조하기 위한 변수가 적절히 추가되었습니다.
372-377: 동적 이미지 표시 로직 승인이미지 URL이 있을 때만 이미지를 표시하고, 없으면 숨기는 로직이 올바르게 구현되었습니다.
참고: HTMLHint에서
src속성이 비어있다고 경고하지만, 이는 동적으로 설정되는 이미지이므로 정상적인 구현입니다.
| @Transactional | ||
| public void addImageToExistingProblem(Long problemId, MultipartFile imageFile) { | ||
| Problem problem = problemDomainService.getProblem(problemId); | ||
|
|
||
| // 1. S3 업로드 | ||
| String key = s3Uploader.upload(imageFile, "problem"); | ||
|
|
||
| // 2. 문제에 이미지 연결 | ||
| problem.addImage(key); // 또는 setImageUrl(List.of(key)) | ||
|
|
||
| // 3. 저장 | ||
| problemDomainService.saveProblem(problem); | ||
| } |
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.
🛠️ Refactor suggestion
메서드 구현 개선 제안
새로운 메서드가 추가되었지만 몇 가지 개선사항이 있습니다:
- S3Directory 열거형 사용: 하드코딩된 "problem" 문자열 대신
S3Directory.PROBLEM.getDir()사용 - 예외 처리 개선: 기존
uploadImageAfterTransaction메서드와 유사한 예외 처리 로직 필요 - 기능 중복:
updateProblemImage메서드와 기능이 중복됨
다음과 같이 개선하는 것을 제안합니다:
@Transactional
public void addImageToExistingProblem(Long problemId, MultipartFile imageFile) {
Problem problem = problemDomainService.getProblem(problemId);
- // 1. S3 업로드
- String key = s3Uploader.upload(imageFile, "problem");
+ // 1. S3 업로드 with error handling
+ String key = uploadImageAfterTransaction(imageFile, problemId);
// 2. 문제에 이미지 연결
- problem.addImage(key); // 또는 setImageUrl(List.of(key))
+ problem.addImage(key);
// 3. 저장
problemDomainService.saveProblem(problem);
}Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In
src/main/java/org/ezcode/codetest/application/problem/service/ProblemService.java
around lines 182 to 194, the addImageToExistingProblem method uses a hardcoded
"problem" string for the S3 upload directory, lacks proper exception handling,
and duplicates functionality found in updateProblemImage. To fix this, replace
the hardcoded string with S3Directory.PROBLEM.getDir(), add exception handling
similar to uploadImageAfterTransaction to manage upload failures gracefully, and
consider refactoring or consolidating this method with updateProblemImage to
avoid redundant code.
작업 내용
Put메소드
api/admin/problems/image/{problmeId}
이미지만 수정 하는 로직
코드 리뷰 전 확인 체크리스트
type :)Summary by CodeRabbit
신규 기능
문서 및 화면 개선