-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 게시글 수정하기 #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 게시글 수정하기 #93
Conversation
Walkthrough게시글 수정 기능이 추가되었습니다. 새로운 DTO(NewPostRequestDto)와 엔티티(Post)의 필드별 수정 메서드가 도입되었으며, 컨트롤러에 PATCH 엔드포인트가 추가되었습니다. 서비스 레이어에서는 게시글 수정, 이미지 업로드, 태그 비교 및 검증 로직이 구현되었습니다. 에러코드도 일부 변경되었습니다. Changes
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: 응답 반환
Possibly related issues
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
|
브랜치 수정해서 재 오픈 예정 |
There was a problem hiding this 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
📒 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/bashPostService의 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 -->
| 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); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
논리 연산자를 사용하세요.
비트 연산자(|) 대신 논리 연산자(||)를 사용해야 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.
| 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.
| SecurityContextHolder.getContext().getAuthentication(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용하지 않는 인증 정보 조회를 제거하세요.
인증 정보를 가져오지만 사용하지 않고 있습니다.
@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.
| 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); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
논리 연산자를 사용하세요.
비트 연산자(&) 대신 논리 연산자(&&)를 사용해야 합니다.
// 아무것도 변경이 없으면 예외처리
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.
| 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.
| @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()); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
게시글 작성자 권한 검증이 필요합니다.
현재 사용자가 게시글 작성자인지 확인하는 로직이 없습니다.
@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.
이슈 번호
작업 내용
Summary by CodeRabbit