-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 댓글 수정(PUT /api/v1/comments/{commentId}) 기능 및 테스트 추가 #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b82aa89
feat: 댓글 수정(PUT /api/v1/comments/{id}) 기능 및 단위/통합 테스트 구현
devikae 3c624c6
feat(comment): 댓글 인라인 수정 UI 구현
devikae 31bf804
fix(seed,config): 스파이크 시드 안전화, DB 유저명 동기화 및 테스트 환경변수 보강
devikae e763171
PR #15 피드백 반영, 댓글 기능 및 테스트 환경 통합
devikae 46f49ec
refactor(comment): PR #15 코드리뷰 피드백 반영
devikae 2fb7ad4
chore(comment): feature/sprint03-comment 병합 및 충돌 해결
devikae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/ikae/snowthing/domain/comment/dto/CommentUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.ikae.snowthing.domain.comment.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record CommentUpdateRequest( | ||
| @NotBlank(message = "댓글 내용은 필수 입력값입니다.") | ||
| @Size(max = 1000, message = "댓글은 최대 1000자까지 입력 가능합니다.") | ||
| String content, | ||
| String anonymousPassword) {} |
5 changes: 5 additions & 0 deletions
5
backend/src/main/java/com/ikae/snowthing/domain/comment/dto/CommentUpdateResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.ikae.snowthing.domain.comment.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record CommentUpdateResponse(Long commentId, String content, LocalDateTime updatedAt) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
backend/src/main/java/com/ikae/snowthing/domain/comment/service/CommentCommandService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package com.ikae.snowthing.domain.comment.service; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.ikae.snowthing.domain.comment.dto.CommentCreateRequest; | ||
| import com.ikae.snowthing.domain.comment.dto.CommentResponse; | ||
| import com.ikae.snowthing.domain.comment.entity.Comment; | ||
| import com.ikae.snowthing.domain.comment.repository.CommentRepository; | ||
| import com.ikae.snowthing.domain.member.entity.Member; | ||
| import com.ikae.snowthing.domain.post.entity.Post; | ||
| import com.ikae.snowthing.domain.post.entity.PostStatus; | ||
| import com.ikae.snowthing.domain.post.repository.PostRepository; | ||
| import com.ikae.snowthing.global.error.ErrorCode; | ||
| import com.ikae.snowthing.global.exception.CustomAuthException; | ||
| import com.ikae.snowthing.global.security.CustomUserDetails; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| class CommentCommandService { | ||
| private static final long MAX_REPLY_COUNT = 100L; | ||
| private final CommentRepository commentRepository; | ||
| private final PostRepository postRepository; | ||
|
|
||
| @Transactional | ||
| CommentResponse createComment( | ||
| String postPublicId, | ||
| CommentCreateRequest request, | ||
| Member member, | ||
| String encodedPassword, | ||
| CustomUserDetails userDetails, | ||
| String clientIp) { | ||
| Post post = | ||
| postRepository | ||
| .findByPublicId(postPublicId) | ||
| .orElseThrow(() -> new CustomAuthException(ErrorCode.POST_NOT_FOUND)); | ||
| if (post.isDeleted() || post.getStatus() != PostStatus.NORMAL) { | ||
| throw new CustomAuthException(ErrorCode.POST_NOT_FOUND); | ||
| } | ||
| Comment parent = null; | ||
| if (request.parentId() != null) { | ||
| Comment requestedParent = | ||
| commentRepository | ||
| .findByIdForUpdate(request.parentId()) | ||
| .orElseThrow( | ||
| () -> | ||
| new CustomAuthException( | ||
| ErrorCode.PARENT_COMMENT_NOT_FOUND)); | ||
| if (!requestedParent.getPost().getId().equals(post.getId())) { | ||
| throw new CustomAuthException(ErrorCode.INVALID_COMMENT_PARENT); | ||
| } | ||
| Long rootId = requestedParent.rootParent().getId(); | ||
| parent = | ||
| commentRepository | ||
| .findByIdForUpdate(rootId) | ||
| .orElseThrow( | ||
| () -> | ||
| new CustomAuthException( | ||
| ErrorCode.PARENT_COMMENT_NOT_FOUND)); | ||
| if (commentRepository.findActiveReplyIdsForUpdate(rootId).size() >= MAX_REPLY_COUNT) { | ||
| throw new CustomAuthException(ErrorCode.COMMENT_REPLY_LIMIT_EXCEEDED); | ||
| } | ||
| } | ||
| Comment comment = | ||
| Comment.create( | ||
| post, | ||
| member, | ||
| parent, | ||
| request.content(), | ||
| clientIp != null ? clientIp : "127.0.0.1", | ||
| request.isAnonymous(), | ||
| encodedPassword); | ||
| CommentResponse response = | ||
| CommentResponse.from(commentRepository.save(comment)) | ||
| .withViewerPermissions( | ||
| userDetails == null ? null : userDetails.getPublicId()); | ||
| postRepository.increaseCommentCount(post.getId()); | ||
| return response; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: devikae/snowthing
Length of output: 155
🏁 Script executed:
Repository: devikae/snowthing
Length of output: 50373
🏁 Script executed:
Repository: devikae/snowthing
Length of output: 50373
🏁 Script executed:
Repository: devikae/snowthing
Length of output: 50373
🏁 Script executed:
Repository: devikae/snowthing
Length of output: 50373
🏁 Script executed:
Repository: devikae/snowthing
Length of output: 26311
🏁 Script executed:
Repository: devikae/snowthing
Length of output: 26107
Broken Authentication (CWE-307): Improper Restriction of Excessive Authentication Attempts
Reachability: External · Exploitability: Moderate
익명 댓글 비밀번호 검증에 시도 횟수 제한을 추가하세요
/api/v1/comments/**는 인증 없이 접근할 수 있습니다.validateUpdatePermission과validateDeletePermission은 실패 시도 제한 없이 매번passwordEncoder.matches를 실행합니다. 비밀번호 정책도 없어"1234"같은 4자리 비밀번호가 허용됩니다.IDENTITY기반Long댓글 ID와 결합하면 공격자는 ID를 열거하고 비밀번호를 대입하여 댓글을 수정하거나 삭제할 수 있습니다. BCrypt 연산과 트랜잭션이 반복되므로 요청 스레드와 DB 커넥션도 고갈될 수 있습니다.두 검증 경로에 분산 원자 카운터, 시도 제한, 잠금 또는 지연을 공통 적용하세요. 성공 시 카운터를 초기화하세요.
ClientIpResolver가 임의의X-Forwarded-For값을 신뢰하지 않도록 신뢰 프록시 범위를 설정하세요. 생성 시 비밀번호의 최소 길이와 엔트로피도 제한하세요.🤖 Prompt for AI Agents
Source: Path instructions
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.
리뷰처리가 완료되었다면 resolve처리를 해주세요
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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 31995
@yyy9942, 현재 PR 브랜치에서 지적 사항이 아직 수정되지 않았습니다.validateUpdatePermission과validateDeletePermission은 여전히 제한 없이passwordEncoder.matches를 실행합니다. 익명 비밀번호에 대한 길이 또는 복잡도 검증도 없습니다. 테스트는 약한 비밀번호인"1234"를 허용합니다.따라서 이 리뷰 스레드는 resolve하지 않습니다.
You are interacting with an AI system.
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.
redis 도입 후 개발 예정
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.