Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package com.example.solidconnection.community.post.domain;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

public enum PostCategory {
전체, 자유, 질문
전체, 자유, 질문;

private static final Set<String> NAMES = Arrays.stream(values())
.map(Enum::name)
.collect(Collectors.toSet());

public static boolean isValid(String name){
return name != null && NAMES.contains(name);
}
Comment on lines +14 to +16
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.

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -137,7 +136,7 @@ private void validateQuestion(Post post) {
}

private void validatePostCategory(String category) {
if (!EnumUtils.isValidEnum(PostCategory.class, category) || category.equals(PostCategory.전체.toString())) {
if (!PostCategory.isValid(category) || category.equals(PostCategory.전체.toString())) {
throw new CustomException(INVALID_POST_CATEGORY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.EnumUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -103,7 +102,7 @@ private Boolean getIsLiked(Post post, SiteUser siteUser) {
}

private PostCategory validatePostCategory(String category) {
if (!EnumUtils.isValidEnum(PostCategory.class, category)) {
if (!PostCategory.isValid(category)) {
throw new CustomException(INVALID_POST_CATEGORY);
}
return PostCategory.valueOf(category);
Expand Down
Loading