Skip to content

refactor: EnumUtils 제거 후 PostCategory에 직접 검증 메서드 추가#707

Merged
sukangpunch merged 2 commits intodevelopfrom
refactor/706-add-enum-name-validation-method
Apr 6, 2026
Merged

refactor: EnumUtils 제거 후 PostCategory에 직접 검증 메서드 추가#707
sukangpunch merged 2 commits intodevelopfrom
refactor/706-add-enum-name-validation-method

Conversation

@sukangpunch
Copy link
Copy Markdown
Contributor

관련 이슈

작업 내용

EnumUtils.isValidEnum()에 의존하던 Enum 검증 로직을 Enum 내부로

  1. 추후 버전업에서 발생할 수 있는 common-lang3 의존성을 추가 할 필요가 없음
  2. 유연한 확장 가능
  3. 높은 응집도

특이 사항

리뷰 요구사항 (선택)

@sukangpunch sukangpunch self-assigned this Apr 1, 2026
@sukangpunch sukangpunch added 리팩터링 최종 리뷰 최소 1명 필수 labels Apr 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Walkthrough

  1. 이 변경사항은 PostCategory 열거형에 유효성 검사 유틸리티 메서드를 추가하고, 두 개의 서비스 클래스에서 Apache Commons의 EnumUtils.isValidEnum()을 새로운 도메인 메서드로 교체합니다.
  2. PostCategory.isValid(String name) 메서드가 추가되어 카테고리 이름의 유효성을 확인합니다.
  3. PostCommandServicePostQueryService에서 기존 검증 로직을 PostCategory.isValid(...)로 통일하였고, 관련된 EnumUtils import를 제거했습니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

변경사항 상세 분석

  1. PostCategory 열거형 개선

    • 열거형 상수 이후에 종료 세미콜론 추가.
    • 모든 열거형 값으로부터 계산된 정적 NAMES 집합 추가.
    • 제공된 문자열이 열거형 상수 이름과 일치하는지 검증하는 공개 정적 메서드 isValid(String name) 도입.
  2. PostCommandService의 유효성 검사 로직 개선

    • EnumUtils.isValidEnum(PostCategory.class, category) 호출을 PostCategory.isValid(category)로 교체.
    • PostCategory.전체 값 거부 및 CustomException(INVALID_POST_CATEGORY) 예외 처리 로직은 유지.
    • EnumUtils import 제거.
  3. PostQueryService의 유효성 검사 로직 개선

    • EnumUtils.isValidEnum(PostCategory.class, category) 호출을 PostCategory.isValid(category)로 교체.
    • 유효하지 않은 카테고리에 대해 CustomException(INVALID_POST_CATEGORY) 예외 처리는 동일하게 유지.
    • EnumUtils import 제거.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 주요 변경사항을 명확하게 반영합니다. EnumUtils 제거 및 PostCategory 검증 메서드 추가라는 핵심 리팩터링 내용을 간결하게 표현했습니다.
Description check ✅ Passed PR 설명이 관련 이슈, 작업 내용을 포함하고 있으나, 특이사항과 리뷰 요구사항 섹션이 비워져 있습니다. 필수 섹션은 충분히 작성되었으므로 통과합니다.
Linked Issues check ✅ Passed PR의 코드 변경사항이 이슈 #706의 목표를 완벽하게 충족합니다. PostCategory enum에 isValid() 검증 메서드를 추가하고, PostCommandService와 PostQueryService에서 EnumUtils 의존성을 제거했습니다.
Out of Scope Changes check ✅ Passed 모든 코드 변경사항이 이슈 #706의 범위 내에 있으며, 예상된 세 파일(PostCategory, PostCommandService, PostQueryService)에만 필요한 수정사항이 적용되었습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/706-add-enum-name-validation-method

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@sukangpunch sukangpunch marked this pull request as ready for review April 1, 2026 11:02
Copy link
Copy Markdown

@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

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 | 🟠 Major

updatePost 메서드에서 카테고리 검증이 누락되어 있습니다.

createPost에서는 validatePostCategory(postCreateRequest.postCategory())를 호출하지만(라인 51), updatePost에서는 이 검증이 없습니다. post.update(postUpdateRequest)가 내부적으로 PostCategory.valueOf()를 직접 호출하므로:

  1. 잘못된 카테고리 문자열 → IllegalArgumentException 발생 (의도된 CustomException 대신)
  2. "전체" 카테고리 → 검증 없이 통과됨
🔧 수정 제안
     `@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

📥 Commits

Reviewing files that changed from the base of the PR and between 3fae55e and 4047e82.

📒 Files selected for processing (3)
  • src/main/java/com/example/solidconnection/community/post/domain/PostCategory.java
  • src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java
  • src/main/java/com/example/solidconnection/community/post/service/PostQueryService.java

Copy link
Copy Markdown
Member

@whqtker whqtker left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 ~! 코드래빗이 집어 준 리뷰 하나만 확인 가능할까요 ??

@sukangpunch
Copy link
Copy Markdown
Contributor Author

고생하셨습니다 ~! 코드래빗이 집어 준 리뷰 하나만 확인 가능할까요 ??

확인 후 수정 했습니다!

Copy link
Copy Markdown

@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.

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4047e82 and 3f50a2a.

📒 Files selected for processing (1)
  • src/main/java/com/example/solidconnection/community/post/service/PostCommandService.java

Copy link
Copy Markdown
Member

@whqtker whqtker left a comment

Choose a reason for hiding this comment

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

확인했습니다 !!

@sukangpunch sukangpunch merged commit be3c6c7 into develop Apr 6, 2026
3 checks passed
@sukangpunch sukangpunch deleted the refactor/706-add-enum-name-validation-method branch April 6, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

리팩터링 최종 리뷰 최소 1명 필수

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: EnumUtil 대신 PostCategory에 검증 메서드 추가

2 participants