Skip to content

Conversation

@youngseo22
Copy link
Contributor

@youngseo22 youngseo22 commented Jun 22, 2025

이슈 번호

#60

작업 내용

  • 게시글 수정하기 기능 구현

Summary by CodeRabbit

  • 신규 기능
    • 게시글을 수정할 수 있는 기능이 추가되었습니다.
    • 게시글 수정 시 변경된 내용이 없을 경우 안내 메시지가 제공됩니다.
  • 버그 수정
    • 이미지 업로드 오류 시 반환되는 상태 코드가 보다 정확하게 변경되었습니다.
  • 기타
    • 게시글 작성 및 수정 요청에 사용할 새로운 데이터 구조가 추가되었습니다.
    • API 응답 및 오류 메시지가 일부 개선되었습니다.

@youngseo22 youngseo22 self-assigned this Jun 22, 2025
@youngseo22 youngseo22 added the ⚡ hotfix issue나 QA에서 문의된 급한 버그 및 오류 해결 label Jun 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 22, 2025

Walkthrough

게시글 수정 기능이 추가되었습니다. 새로운 DTO(NewPostRequestDto)와 엔티티(Post)의 필드별 수정 메서드가 도입되었으며, 컨트롤러에 PATCH 엔드포인트가 추가되었습니다. 서비스 레이어에서는 게시글 수정, 이미지 업로드, 태그 비교 및 검증 로직이 구현되었습니다. 에러코드도 일부 변경되었습니다.

Changes

파일/경로 변경 요약
.../controller/PostController.java 게시글 수정 PATCH 엔드포인트 추가, 주석 보강, NewPostRequestDto import
.../domain/post/Post.java 게시글 필드별 수정 메서드, 태그 클리어, 수정일시 갱신 메서드 추가
.../dto/post/NewPostRequestDto.java 게시글 생성/수정용 DTO 신설, Lombok @Getter 적용
.../exception/ErrorCode.java IMAGE_UPLOAD_FAILED 상태 변경, NO_CONTENT_CHANGED 에러코드 추가
.../service/PostService.java 게시글 수정, 이미지 업로드, 태그 비교/검증, NewPostRequestDto 검증 메서드 추가

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PostController
    participant PostService
    participant PostRepository
    participant TagRepository
    participant Post

    Client->>PostController: PATCH /posts/{postId}/edit (NewPostRequestDto)
    PostController->>PostService: editPost(postId, NewPostRequestDto)
    PostService->>PostRepository: findById(postId)
    PostService->>TagRepository: fetchAndValidateTags(tags)
    PostService->>Post: 필드별 변경사항 비교 및 수정
    PostService->>Post: updateEditedAt()
    PostService->>Post: clearTags(), addTags()
    PostService-->>PostController: 수정 성공/실패 응답
    PostController-->>Client: 응답 반환
Loading

Possibly related issues

Poem

🐇
새싹처럼 돋아난 수정의 길,
PATCH 한 번에 글이 새로워질,
DTO도 태그도 모두 새 단장,
토끼는 깡충, 코드를 찬양!
"수정 완료!" 라며 귀를 쫑긋,
FixLog의 봄은 오늘도 싱긋.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@youngseo22 youngseo22 changed the base branch from main to develop June 22, 2025 10:39
@youngseo22 youngseo22 closed this Jun 22, 2025
@youngseo22
Copy link
Contributor Author

브랜치 수정해서 재 오픈 예정

Copy link
Contributor

@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: 4

🧹 Nitpick comments (1)
src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java (1)

8-21: 입력 검증 어노테이션 추가를 고려하세요.

DTO 레벨에서 기본적인 입력 검증을 추가하면 더 견고한 API가 됩니다.

+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+
 @Getter
 public class NewPostRequestDto {
+    @NotBlank(message = "제목은 필수입니다")
     private String postTitle;
     private String coverImageUrl;
+    @NotBlank(message = "문제 설명은 필수입니다")
     private String problem;
+    @NotBlank(message = "에러 메시지는 필수입니다")
     private String errorMessage;
+    @NotBlank(message = "환경 정보는 필수입니다")
     private String environment;
+    @NotBlank(message = "재현 코드는 필수입니다")
     private String reproduceCode;
+    @NotBlank(message = "해결 코드는 필수입니다")
     private String solutionCode;
     private String causeAnalysis;
     private String referenceLink;
     private String extraContent;
 
+    @NotNull(message = "태그는 필수입니다")
     private List<Long> tags;
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4bb590 and 9c012c2.

📒 Files selected for processing (5)
  • src/main/java/com/example/FixLog/controller/PostController.java (2 hunks)
  • src/main/java/com/example/FixLog/domain/post/Post.java (1 hunks)
  • src/main/java/com/example/FixLog/dto/post/NewPostRequestDto.java (1 hunks)
  • src/main/java/com/example/FixLog/exception/ErrorCode.java (1 hunks)
  • src/main/java/com/example/FixLog/service/PostService.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (3)
src/main/java/com/example/FixLog/exception/ErrorCode.java (1)

33-34: 에러 코드 변경이 적절합니다!

IMAGE_UPLOAD_FAILED의 HTTP 상태를 NOT_FOUND에서 BAD_REQUEST로 변경한 것과 NO_CONTENT_CHANGED 에러 코드를 추가한 것이 적절합니다.

src/main/java/com/example/FixLog/controller/PostController.java (1)

35-40: ```shell
#!/bin/bash

PostService의 editPost 메서드 구현 및 권한 검증 로직 확인

PostService 클래스 위치 확인

rg "class PostService" -n src

editPost 메서드 정의 및 내부 로직(권한 검증) 확인

rg "editPost" -n src -A10


</details>
<details>
<summary>src/main/java/com/example/FixLog/domain/post/Post.java (1)</summary>

`82-118`: **필드별 수정 메서드가 잘 구현되었습니다!**

일관된 네이밍 규칙과 명확한 책임을 가진 메서드들로 구현되었습니다.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines +153 to +157
if (newPostRequestDto.getPostTitle().isBlank() | newPostRequestDto.getProblem().isBlank()
| newPostRequestDto.getErrorMessage().isBlank() | newPostRequestDto.getEnvironment().isBlank()
| newPostRequestDto.getReproduceCode().isBlank() | newPostRequestDto.getSolutionCode().isBlank())
throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

논리 연산자를 사용하세요.

비트 연산자(|) 대신 논리 연산자(||)를 사용해야 short-circuit evaluation이 가능합니다.

 private void validatePost(NewPostRequestDto newPostRequestDto){
-    if (newPostRequestDto.getPostTitle().isBlank() | newPostRequestDto.getProblem().isBlank()
-        | newPostRequestDto.getErrorMessage().isBlank() | newPostRequestDto.getEnvironment().isBlank()
-        | newPostRequestDto.getReproduceCode().isBlank() | newPostRequestDto.getSolutionCode().isBlank())
+    if (newPostRequestDto.getPostTitle().isBlank() || newPostRequestDto.getProblem().isBlank()
+        || newPostRequestDto.getErrorMessage().isBlank() || newPostRequestDto.getEnvironment().isBlank()
+        || newPostRequestDto.getReproduceCode().isBlank() || newPostRequestDto.getSolutionCode().isBlank())
         throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (newPostRequestDto.getPostTitle().isBlank() | newPostRequestDto.getProblem().isBlank()
| newPostRequestDto.getErrorMessage().isBlank() | newPostRequestDto.getEnvironment().isBlank()
| newPostRequestDto.getReproduceCode().isBlank() | newPostRequestDto.getSolutionCode().isBlank())
throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING);
}
private void validatePost(NewPostRequestDto newPostRequestDto){
if (newPostRequestDto.getPostTitle().isBlank() || newPostRequestDto.getProblem().isBlank()
|| newPostRequestDto.getErrorMessage().isBlank() || newPostRequestDto.getEnvironment().isBlank()
|| newPostRequestDto.getReproduceCode().isBlank() || newPostRequestDto.getSolutionCode().isBlank())
throw new CustomException(ErrorCode.REQUIRED_CONTENT_MISSING);
}
🤖 Prompt for AI Agents
In src/main/java/com/example/FixLog/service/PostService.java around lines 153 to
157, replace the bitwise OR operator '|' with the logical OR operator '||' in
the if condition to enable short-circuit evaluation and improve performance and
correctness.

Comment on lines +162 to +163
SecurityContextHolder.getContext().getAuthentication();

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

사용하지 않는 인증 정보 조회를 제거하세요.

인증 정보를 가져오지만 사용하지 않고 있습니다.

 @Transactional
 public String uploadImage(MultipartFile imageFile){
-    SecurityContextHolder.getContext().getAuthentication();
-
     if (imageFile == null || imageFile.isEmpty()){
         throw new CustomException(ErrorCode.IMAGE_UPLOAD_FAILED);
     }
🤖 Prompt for AI Agents
In src/main/java/com/example/FixLog/service/PostService.java at lines 162 to
163, the code retrieves the authentication information using
SecurityContextHolder.getContext().getAuthentication() but does not use it
anywhere. Remove this unused retrieval statement to clean up the code and avoid
unnecessary operations.

Comment on lines +182 to +194
if (Objects.equals(post.getPostTitle(), newPostRequestDto.getPostTitle())
& Objects.equals(post.getCoverImage(), newPostRequestDto.getCoverImageUrl())
& Objects.equals(post.getProblem(), newPostRequestDto.getProblem())
& Objects.equals(post.getErrorMessage(), newPostRequestDto.getErrorMessage())
& Objects.equals(post.getEnvironment(), newPostRequestDto.getEnvironment())
& Objects.equals(post.getReproduceCode(), newPostRequestDto.getReproduceCode())
& Objects.equals(post.getSolutionCode(), newPostRequestDto.getSolutionCode())
& Objects.equals(post.getCauseAnalysis(), newPostRequestDto.getCauseAnalysis())
& Objects.equals(post.getReferenceLink(), newPostRequestDto.getReferenceLink())
& Objects.equals(post.getExtraContent(), newPostRequestDto.getExtraContent())
& compareTags(post.getPostTags(), tags)){
throw new CustomException(ErrorCode.NO_CONTENT_CHANGED);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

논리 연산자를 사용하세요.

비트 연산자(&) 대신 논리 연산자(&&)를 사용해야 합니다.

 // 아무것도 변경이 없으면 예외처리
 if (Objects.equals(post.getPostTitle(), newPostRequestDto.getPostTitle())
-    & Objects.equals(post.getCoverImage(), newPostRequestDto.getCoverImageUrl())
-    & Objects.equals(post.getProblem(), newPostRequestDto.getProblem())
-    & Objects.equals(post.getErrorMessage(), newPostRequestDto.getErrorMessage())
-    & Objects.equals(post.getEnvironment(), newPostRequestDto.getEnvironment())
-    & Objects.equals(post.getReproduceCode(), newPostRequestDto.getReproduceCode())
-    & Objects.equals(post.getSolutionCode(), newPostRequestDto.getSolutionCode())
-    & Objects.equals(post.getCauseAnalysis(), newPostRequestDto.getCauseAnalysis())
-    & Objects.equals(post.getReferenceLink(), newPostRequestDto.getReferenceLink())
-    & Objects.equals(post.getExtraContent(), newPostRequestDto.getExtraContent())
-    & compareTags(post.getPostTags(), tags)){
+    && Objects.equals(post.getCoverImage(), newPostRequestDto.getCoverImageUrl())
+    && Objects.equals(post.getProblem(), newPostRequestDto.getProblem())
+    && Objects.equals(post.getErrorMessage(), newPostRequestDto.getErrorMessage())
+    && Objects.equals(post.getEnvironment(), newPostRequestDto.getEnvironment())
+    && Objects.equals(post.getReproduceCode(), newPostRequestDto.getReproduceCode())
+    && Objects.equals(post.getSolutionCode(), newPostRequestDto.getSolutionCode())
+    && Objects.equals(post.getCauseAnalysis(), newPostRequestDto.getCauseAnalysis())
+    && Objects.equals(post.getReferenceLink(), newPostRequestDto.getReferenceLink())
+    && Objects.equals(post.getExtraContent(), newPostRequestDto.getExtraContent())
+    && compareTags(post.getPostTags(), tags)){
     throw new CustomException(ErrorCode.NO_CONTENT_CHANGED);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (Objects.equals(post.getPostTitle(), newPostRequestDto.getPostTitle())
& Objects.equals(post.getCoverImage(), newPostRequestDto.getCoverImageUrl())
& Objects.equals(post.getProblem(), newPostRequestDto.getProblem())
& Objects.equals(post.getErrorMessage(), newPostRequestDto.getErrorMessage())
& Objects.equals(post.getEnvironment(), newPostRequestDto.getEnvironment())
& Objects.equals(post.getReproduceCode(), newPostRequestDto.getReproduceCode())
& Objects.equals(post.getSolutionCode(), newPostRequestDto.getSolutionCode())
& Objects.equals(post.getCauseAnalysis(), newPostRequestDto.getCauseAnalysis())
& Objects.equals(post.getReferenceLink(), newPostRequestDto.getReferenceLink())
& Objects.equals(post.getExtraContent(), newPostRequestDto.getExtraContent())
& compareTags(post.getPostTags(), tags)){
throw new CustomException(ErrorCode.NO_CONTENT_CHANGED);
}
// 아무것도 변경이 없으면 예외처리
if (Objects.equals(post.getPostTitle(), newPostRequestDto.getPostTitle())
&& Objects.equals(post.getCoverImage(), newPostRequestDto.getCoverImageUrl())
&& Objects.equals(post.getProblem(), newPostRequestDto.getProblem())
&& Objects.equals(post.getErrorMessage(), newPostRequestDto.getErrorMessage())
&& Objects.equals(post.getEnvironment(), newPostRequestDto.getEnvironment())
&& Objects.equals(post.getReproduceCode(), newPostRequestDto.getReproduceCode())
&& Objects.equals(post.getSolutionCode(), newPostRequestDto.getSolutionCode())
&& Objects.equals(post.getCauseAnalysis(), newPostRequestDto.getCauseAnalysis())
&& Objects.equals(post.getReferenceLink(), newPostRequestDto.getReferenceLink())
&& Objects.equals(post.getExtraContent(), newPostRequestDto.getExtraContent())
&& compareTags(post.getPostTags(), tags)) {
throw new CustomException(ErrorCode.NO_CONTENT_CHANGED);
}
🤖 Prompt for AI Agents
In src/main/java/com/example/FixLog/service/PostService.java around lines 182 to
194, replace all bitwise AND operators (&) used between the Objects.equals()
calls with logical AND operators (&&) to correctly evaluate the combined boolean
expressions.

Comment on lines +172 to +180
@Transactional
public void editPost(Long postId, NewPostRequestDto newPostRequestDto) {
Member member = memberService.getCurrentMemberInfo();
Post post = postRepository.findById(postId)
.orElseThrow(() -> new CustomException(ErrorCode.POST_NOT_FOUND));

// 북마크 카테고리별로 선택 제한 두기
List<Tag> tags = fetchAndValidateTags(newPostRequestDto.getTags());

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

게시글 작성자 권한 검증이 필요합니다.

현재 사용자가 게시글 작성자인지 확인하는 로직이 없습니다.

 @Transactional
 public void editPost(Long postId, NewPostRequestDto newPostRequestDto) {
     Member member = memberService.getCurrentMemberInfo();
     Post post = postRepository.findById(postId)
             .orElseThrow(() -> new CustomException(ErrorCode.POST_NOT_FOUND));
 
+    // 게시글 작성자 확인
+    if (!post.getUserId().equals(member)) {
+        throw new CustomException(ErrorCode.ACCESS_DENIED);
+    }
+
     // 북마크 카테고리별로 선택 제한 두기
     List<Tag> tags = fetchAndValidateTags(newPostRequestDto.getTags());
🤖 Prompt for AI Agents
In src/main/java/com/example/FixLog/service/PostService.java around lines 172 to
180, the editPost method lacks a check to verify that the current user is the
author of the post. Add a validation step after retrieving the post to compare
the post's author with the current member, and if they do not match, throw an
appropriate exception to enforce author-only edit permissions.

@youngseo22 youngseo22 deleted the feat/#60-editPost-ys branch June 22, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚡ hotfix issue나 QA에서 문의된 급한 버그 및 오류 해결

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants