Skip to content

Conversation

@Kimminu7
Copy link
Collaborator

@Kimminu7 Kimminu7 commented Jul 7, 2025

작업 내용

  • 문제 이미지 수정 로직, UI 부분 추가

Put메소드
api/admin/problems/image/{problmeId}
이미지만 수정 하는 로직

image

코드 리뷰 전 확인 체크리스트

  • 불필요한 콘솔 로그, 주석 제거
  • 커밋 메시지 컨벤션 준수 (type : )
  • 기능 정상 동작 확인

Summary by CodeRabbit

  • 신규 기능

    • 문제 상세 정보에 이미지 URL 표시 기능이 추가되었습니다.
    • 관리자가 기존 문제에 이미지를 별도로 업로드 및 수정할 수 있는 엔드포인트가 추가되었습니다.
    • 문제 상세 화면에서 문제 이미지가 있을 경우 자동으로 표시됩니다.
  • 문서 및 화면 개선

    • 문제 수정 관련 설명이 "문제 전체 수정"으로 명확하게 변경되었습니다.

@Kimminu7 Kimminu7 self-assigned this Jul 7, 2025
@Kimminu7 Kimminu7 added the documentation Improvements or additions to documentation label Jul 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 7, 2025

Walkthrough

문제 이미지 URL을 응답 DTO에 추가하고, 기존 문제에 이미지를 추가하는 서비스 메서드와 관리자 전용 이미지 수정 엔드포인트를 신설했습니다. 또한, 문제 상세 HTML에 이미지 표시 영역을 추가하고, JS에서 동적으로 이미지를 표시하도록 수정했습니다.

Changes

파일/경로 변경 요약
.../application/problem/dto/response/ProblemDetailResponse.java imageUrl 필드 추가, 팩토리 메서드에서 첫 번째 이미지 URL 할당 로직 반영
.../application/problem/service/ProblemService.java addImageToExistingProblem(Long, MultipartFile) 공개 메서드 신설, S3 업로드 및 문제 엔티티 저장 포함
.../presentation/problemmanagement/problem/ProblemAdminController.java 전체 수정 오퍼레이션 설명 수정, 문제 이미지 수정용 PUT 엔드포인트 및 권한 검사 추가
.../resources/templates/test-submit.html 문제 상세에 이미지 영역 및 img 태그 추가, JS에서 imageUrl 동적 표시 및 토글 처리

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
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • minjee2758
  • NCookies
  • pokerbearkr
  • chat26666
  • thezz9

Poem

🐰
문제에 사진이 첨가됐어요,
이미지는 S3로 척척 올려요.
관리자는 버튼 한 번,
HTML엔 사진이 번쩍!
토끼도 감탄한 새 기능,
코드에 봄바람 솔솔 부네요.
🖼️✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 문서와 구현 간 불일치 수정

새로운 이미지 수정 엔드포인트에 몇 가지 불일치가 있습니다:

  1. 응답 코드 불일치: @ApiResponse에서는 200을 명시하지만 실제로는 204를 반환
  2. 메서드 설명 개선: "문제 이미지 수정"이라고 했지만 서비스 메서드명은 "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

📥 Commits

Reviewing files that changed from the base of the PR and between c2ada1a and 0b14547.

📒 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 속성이 비어있다고 경고하지만, 이는 동적으로 설정되는 이미지이므로 정상적인 구현입니다.

Comment on lines +182 to +194
@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);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

메서드 구현 개선 제안

새로운 메서드가 추가되었지만 몇 가지 개선사항이 있습니다:

  1. S3Directory 열거형 사용: 하드코딩된 "problem" 문자열 대신 S3Directory.PROBLEM.getDir() 사용
  2. 예외 처리 개선: 기존 uploadImageAfterTransaction 메서드와 유사한 예외 처리 로직 필요
  3. 기능 중복: 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.

@pokerbearkr pokerbearkr merged commit 113458d into dev Jul 7, 2025
2 checks passed
@pokerbearkr pokerbearkr deleted the refactor/problem branch July 7, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants