refactor: EnumUtils 제거 후 PostCategory에 직접 검증 메서드 추가#707
Conversation
Walkthrough
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 변경사항 상세 분석
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java (1)
70-89:⚠️ Potential issue | 🟠 MajorupdatePost 메서드에서 카테고리 검증이 누락되어 있습니다.
createPost에서는validatePostCategory(postCreateRequest.postCategory())를 호출하지만(라인 51),updatePost에서는 이 검증이 없습니다.post.update(postUpdateRequest)가 내부적으로PostCategory.valueOf()를 직접 호출하므로:
- 잘못된 카테고리 문자열 →
IllegalArgumentException발생 (의도된CustomException대신)- "전체" 카테고리 → 검증 없이 통과됨
🔧 수정 제안
`@Transactional` public PostUpdateResponse updatePost(long siteUserId, Long postId, PostUpdateRequest postUpdateRequest, List<MultipartFile> imageFile) { SiteUser siteUser = siteUserRepository.findById(siteUserId) .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); // 유효성 검증 Post post = postRepository.getById(postId); validateOwnership(post, siteUser); validateQuestion(post); + validatePostCategory(postUpdateRequest.postCategory()); validateFileSize(imageFile);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java` around lines 70 - 89, The updatePost method is missing category validation; before calling post.update(postUpdateRequest) add a call to validatePostCategory(postUpdateRequest.postCategory()) (same validator used in createPost) so invalid category strings are handled via CustomException and the "전체" category is rejected per existing rules; place this validation after validateFileSize(imageFile) and before post.update to ensure Post.update never directly triggers PostCategory.valueOf() on bad input.
🤖 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/com/example/solidconnection/community/post/domain/PostCategory.java`:
- Around line 14-16: The updatePost() path is missing category validation:
before calling post.update(...) add a call to
validatePostCategory(postUpdateRequest.postCategory()) so invalid categories are
rejected with the same CustomException(INVALID_POST_CATEGORY) as createPost();
this prevents Post.update() from throwing an unchecked IllegalArgumentException
from PostCategory.valueOf(...) and enforces the same "exclude 전체" rule that
validatePostCategory() applies.
---
Outside diff comments:
In
`@src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java`:
- Around line 70-89: The updatePost method is missing category validation;
before calling post.update(postUpdateRequest) add a call to
validatePostCategory(postUpdateRequest.postCategory()) (same validator used in
createPost) so invalid category strings are handled via CustomException and the
"전체" category is rejected per existing rules; place this validation after
validateFileSize(imageFile) and before post.update to ensure Post.update never
directly triggers PostCategory.valueOf() on bad input.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 75599dbf-9d87-48cd-bfb5-c16e992447d3
📒 Files selected for processing (3)
src/main/java/com/example/solidconnection/community/post/domain/PostCategory.javasrc/main/java/com/example/solidconnection/community/post/service/PostCommandService.javasrc/main/java/com/example/solidconnection/community/post/service/PostQueryService.java
src/main/java/com/example/solidconnection/community/post/domain/PostCategory.java
Show resolved
Hide resolved
whqtker
left a comment
There was a problem hiding this comment.
고생하셨습니다 ~! 코드래빗이 집어 준 리뷰 하나만 확인 가능할까요 ??
확인 후 수정 했습니다! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java (1)
77-79: 1. 권한 검증을 카테고리 검증보다 먼저 수행해 주세요.현재 순서에서는 비소유자 요청에도
INVALID_POST_CATEGORY가 먼저 반환될 수 있어, 접근 제어 에러 일관성이 깨집니다.updatePost에서는 권한 검증을 우선하는 편이 안전합니다.순서 조정 제안
- validatePostCategory(postUpdateRequest.postCategory()); - validateOwnership(post, siteUser); + validateOwnership(post, siteUser); + validatePostCategory(postUpdateRequest.postCategory()); validateQuestion(post); validateFileSize(imageFile);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java` around lines 77 - 79, Reorder the validation calls in PostCommandService.updatePost so ownership is checked before category: call validateOwnership(post, siteUser) first, then validatePostCategory(postUpdateRequest.postCategory()), and finally validateQuestion(post); this ensures validateOwnership runs prior to validatePostCategory and prevents non-owners from receiving INVALID_POST_CATEGORY errors.
🤖 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/com/example/solidconnection/community/post/service/PostCommandService.java`:
- Around line 77-79: Reorder the validation calls in
PostCommandService.updatePost so ownership is checked before category: call
validateOwnership(post, siteUser) first, then
validatePostCategory(postUpdateRequest.postCategory()), and finally
validateQuestion(post); this ensures validateOwnership runs prior to
validatePostCategory and prevents non-owners from receiving
INVALID_POST_CATEGORY errors.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 838e4822-79c7-4f3b-8c56-0e5ca5f06939
📒 Files selected for processing (1)
src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java
관련 이슈
작업 내용
EnumUtils.isValidEnum()에 의존하던 Enum 검증 로직을 Enum 내부로
특이 사항
리뷰 요구사항 (선택)