refactor: EnumUtils 제거 후 PostCategory에 직접 검증 메서드 추가#707
refactor: EnumUtils 제거 후 PostCategory에 직접 검증 메서드 추가#707sukangpunch wants to merge 1 commit intodevelopfrom
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
| public static boolean isValid(String name){ | ||
| return name != null && NAMES.contains(name); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check if validatePostCategory is called before post.update() in updatePost method
# Search for updatePost method implementation and check for validatePostCategory call
rg -nA 30 'public PostUpdateResponse updatePost' --type javaRepository: solid-connection/solid-connect-server
Length of output: 4170
🏁 Script executed:
#!/bin/bash
# Check Post.update() method implementation
rg -nA 20 'public.*void update\(PostUpdateRequest' src/main/java/com/example/solidconnection/community/post/domain/Post.javaRepository: solid-connection/solid-connect-server
Length of output: 348
🏁 Script executed:
#!/bin/bash
# Check if validatePostCategory method exists in PostCommandService
rg -n 'validatePostCategory' src/main/java/com/example/solidconnection/community/post/service/PostCommandService.javaRepository: solid-connection/solid-connect-server
Length of output: 208
🏁 Script executed:
#!/bin/bash
# Check PostCategory.valueOf() usage
rg -n 'PostCategory.valueOf' src/main/java/com/example/solidconnection/community/post/domain/Post.javaRepository: solid-connection/solid-connect-server
Length of output: 163
🏁 Script executed:
#!/bin/bash
# Get full validatePostCategory implementation
rg -nA 5 'private void validatePostCategory' src/main/java/com/example/solidconnection/community/post/service/PostCommandService.javaRepository: solid-connection/solid-connect-server
Length of output: 334
🏁 Script executed:
#!/bin/bash
# Check PostCategory enum implementation
rg -nA 15 'public enum PostCategory' src/main/java/com/example/solidconnection/community/post/domain/PostCategory.javaRepository: solid-connection/solid-connect-server
Length of output: 404
updatePost() 메서드에서 카테고리 검증이 누락되어 있습니다.
updatePost() 메서드를 확인한 결과, 다음과 같은 문제가 있습니다:
-
검증 로직 부재
createPost()메서드에서는 라인 51에서validatePostCategory()호출이 있습니다.updatePost()메서드는 검증 로직(라인 75-79의 validateOwnership, validateQuestion, validateFileSize)이 있음에도 불구하고,validatePostCategory()호출이 누락되어 있습니다.
-
예외 처리의 일관성 문제
Post.update()메서드(라인 86)에서PostCategory.valueOf(postUpdateRequest.postCategory())를 직접 호출합니다.- 유효하지 않은 카테고리 값이 들어올 경우,
IllegalArgumentException이 발생합니다. - 대신
validatePostCategory()를 호출하면CustomException(INVALID_POST_CATEGORY)로 일관성 있게 처리됩니다.
-
추가 사항
PostCategory.valueOf()는 "전체" 카테고리를 포함하여 변환하지만,validatePostCategory()는 "전체"를 명시적으로 거부합니다.- 기존 코드에서는 이 차이로 인한 불일치가 발생합니다.
해결책: updatePost() 메서드에서 post.update() 호출 전에 validatePostCategory(postUpdateRequest.postCategory())를 추가하세요.
🤖 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/domain/PostCategory.java`
around lines 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.
관련 이슈
작업 내용
EnumUtils.isValidEnum()에 의존하던 Enum 검증 로직을 Enum 내부로
특이 사항
리뷰 요구사항 (선택)