Skip to content

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

Open
sukangpunch wants to merge 1 commit intodevelopfrom
refactor/706-add-enum-name-validation-method
Open

refactor: EnumUtils 제거 후 PostCategory에 직접 검증 메서드 추가#707
sukangpunch wants to merge 1 commit 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

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

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

변경사항 상세 분석

아래는 이번 개정사항의 주요 변경들입니다:

  1. PostCategory 열거형 개선

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

    • Apache Commons의 EnumUtils.isValidEnum(PostCategory.class, category) 호출을 새로운 PostCategory.isValid(category) 메서드로 교체
    • 기존의 PostCategory.전체 값 거부 및 예외 처리 로직은 유지
    • 불필요한 EnumUtils import 제거
  3. PostQueryService의 유효성 검사 로직 개선

    • Apache Commons의 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 설명이 관련 이슈(#706)를 명시하고, 작업 내용과 변경의 목적(의존성 제거, 확장성, 응집도 향상)을 구체적으로 기술하여 템플릿의 필수 섹션을 충실히 채우고 있습니다.
Linked Issues check ✅ Passed PostCategory enum에 isValid(String name) 정적 메서드를 구현하고, PostCommandService와 PostQueryService에서 EnumUtils 대신 해당 메서드를 사용하도록 변경하여 이슈 #706의 모든 주요 목표를 충족하고 있습니다.
Out of Scope Changes check ✅ Passed 모든 코드 변경이 이슈 #706의 범위 내에서 EnumUtils 의존성을 제거하고 PostCategory에 검증 메서드를 추가하는 작업에만 집중하고 있으며, 범위 외 변경사항이 없습니다.

✏️ 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

Comment on lines +14 to +16
public static boolean isValid(String name){
return name != null && NAMES.contains(name);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 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 java

Repository: 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.java

Repository: 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.java

Repository: 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.java

Repository: 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.java

Repository: 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.java

Repository: solid-connection/solid-connect-server

Length of output: 404


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

updatePost() 메서드를 확인한 결과, 다음과 같은 문제가 있습니다:

  1. 검증 로직 부재

    • createPost() 메서드에서는 라인 51에서 validatePostCategory() 호출이 있습니다.
    • updatePost() 메서드는 검증 로직(라인 75-79의 validateOwnership, validateQuestion, validateFileSize)이 있음에도 불구하고, validatePostCategory() 호출이 누락되어 있습니다.
  2. 예외 처리의 일관성 문제

    • Post.update() 메서드(라인 86)에서 PostCategory.valueOf(postUpdateRequest.postCategory())를 직접 호출합니다.
    • 유효하지 않은 카테고리 값이 들어올 경우, IllegalArgumentException이 발생합니다.
    • 대신 validatePostCategory()를 호출하면 CustomException(INVALID_POST_CATEGORY)로 일관성 있게 처리됩니다.
  3. 추가 사항

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

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에 검증 메서드 추가

1 participant