-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 댓글 생성(2-Depth 평탄화, 100개 상한) 및 루트 Batch + 대댓글 분리 페이징 조회 구현 #14
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
Open
devikae
wants to merge
9
commits into
feature/sprint03-comment
Choose a base branch
from
feature/sprint03-comment-cr
base: feature/sprint03-comment
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0e54658
docs: Sprint 03 댓글 도메인 공식 설계 문서(ADR-001, 정책 명세서) 및 공통 픽스처 추가
devikae 052784e
docs: Sprint 03 공식 댓글 API 명세서 추가 및 C(생성) 기능 구현 커밋
devikae 33fef4d
feat(comment): 댓글 생성 동시성 제어 및 MySQL 테스트 보강
devikae bfbb5e6
feat(comment): 댓글 조회 API 및 프론트엔드 연동
devikae a4490a9
chore(comment): 댓글 실행환경 및 데이터베이스 설정 반영
devikae 4396c24
docs(comment): Sprint 03 댓글 C/R 작업 기록 반영
devikae 834b313
ci: Gemini PR 코드 리뷰 수동 명령어(/gemini-review) 안정화
devikae a930fc6
perf(comment): 대댓글 복합 인덱스 is_deleted 선행 최적화 및 DB 환경변수 동기화
devikae 14ff543
refactor(comment): PR #14 코드리뷰 피드백 반영
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copy this file to .env and replace the placeholders with local-only values. | ||
| # Never commit the generated .env file. | ||
| SNOWTHING_DB_USERNAME=snowuser | ||
| SNOWTHING_DB_PASSWORD=replace-with-a-local-password | ||
| SNOWTHING_DB_ROOT_PASSWORD=replace-with-a-different-root-password | ||
|
|
||
| # Optional credentials for CommentCreateTest's fixed snowthing_test MySQL schema. | ||
| SNOWTHING_TEST_DB_USERNAME=snowuser | ||
| SNOWTHING_TEST_DB_PASSWORD=replace-with-a-local-test-password |
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
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
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/com/ikae/snowthing/domain/comment/dto/CommentReplyListResponse.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,14 @@ | ||
| package com.ikae.snowthing.domain.comment.dto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record CommentReplyListResponse( | ||
| Long rootCommentId, | ||
| long totalReplyCount, | ||
| List<CommentResponse> replies, | ||
| Long nextCursor, | ||
| boolean hasNext) { | ||
| public CommentReplyListResponse { | ||
| replies = replies == null ? List.of() : List.copyOf(replies); | ||
| } | ||
| } |
102 changes: 87 additions & 15 deletions
102
backend/src/main/java/com/ikae/snowthing/domain/comment/dto/CommentResponse.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 |
|---|---|---|
| @@ -1,35 +1,107 @@ | ||
| package com.ikae.snowthing.domain.comment.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import com.ikae.snowthing.domain.comment.entity.Comment; | ||
| import com.ikae.snowthing.domain.member.entity.Member; | ||
| import com.ikae.snowthing.global.util.WriterDisplayFormatter; | ||
|
|
||
| public record CommentResponse( | ||
| Long commentId, | ||
| Long postId, | ||
| Long parentId, | ||
| String writerName, | ||
| WriterResponse writer, | ||
| boolean isAnonymous, | ||
| String writerIp, | ||
| String content, | ||
| boolean isDeleted, | ||
| LocalDateTime createdAt, | ||
| List<CommentResponse> children) { | ||
| public static CommentResponse from(Comment comment) { | ||
| String writerName = | ||
| WriterDisplayFormatter.format( | ||
| comment.isAnonymous(), comment.getMember(), comment.getWriterIp()); | ||
| long replyCount, | ||
| List<CommentResponse> previewReplies, | ||
| boolean hasMoreReplies, | ||
| LocalDateTime createdAt) { | ||
|
|
||
| private static final String ANONYMOUS_NAME = "ㅇㅇ"; | ||
|
|
||
| public CommentResponse { | ||
| previewReplies = previewReplies == null ? List.of() : List.copyOf(previewReplies); | ||
| } | ||
|
|
||
| String displayContent = comment.isDeleted() ? "삭제된 댓글입니다." : comment.getContent(); | ||
| Long parentIdValue = comment.getParent() != null ? comment.getParent().getId() : null; | ||
| public record WriterResponse(String publicId, String nickname, String profileImageUrl) {} | ||
|
|
||
| public static CommentResponse from(Comment comment) { | ||
| Member member = comment.getMember(); | ||
| WriterResponse writer = | ||
| !comment.isAnonymous() && member != null | ||
| ? new WriterResponse( | ||
| member.getPublicId(), | ||
| member.getNickname(), | ||
| member.getProfileImageUrl()) | ||
| : null; | ||
| return new CommentResponse( | ||
| comment.getId(), | ||
| parentIdValue, | ||
| writerName, | ||
| displayContent, | ||
| comment.getPost().getId(), | ||
| comment.getParent() == null ? null : comment.getParent().getId(), | ||
| writer, | ||
| comment.isAnonymous(), | ||
| WriterDisplayFormatter.maskIp(comment.getWriterIp()), | ||
| comment.isDeleted() ? "삭제된 댓글입니다." : comment.getContent(), | ||
| comment.isDeleted(), | ||
| comment.getCreatedAt(), | ||
| new ArrayList<>()); | ||
| 0, | ||
| List.of(), | ||
| false, | ||
| comment.getCreatedAt()); | ||
| } | ||
|
|
||
| public CommentResponse withPreviewReplies(List<CommentResponse> replies) { | ||
| return new CommentResponse( | ||
| commentId, | ||
| postId, | ||
| parentId, | ||
| writer, | ||
| isAnonymous, | ||
| writerIp, | ||
| content, | ||
| isDeleted, | ||
| replyCount, | ||
| replies, | ||
| hasMoreReplies, | ||
| createdAt); | ||
| } | ||
|
|
||
| public CommentResponse withReplyInfo( | ||
| long replyCount, boolean hasMoreReplies, List<CommentResponse> replies) { | ||
| return new CommentResponse( | ||
| commentId, | ||
| postId, | ||
| parentId, | ||
| writer, | ||
| isAnonymous, | ||
| writerIp, | ||
| content, | ||
| isDeleted, | ||
| replyCount, | ||
| replies, | ||
| hasMoreReplies, | ||
| createdAt); | ||
| } | ||
|
|
||
| public List<CommentResponse> children() { | ||
| return previewReplies; | ||
| } | ||
|
|
||
| public String writerName() { | ||
| if (!isAnonymous) { | ||
| return (writer != null && writer.nickname() != null) | ||
| ? writer.nickname() | ||
| : ANONYMOUS_NAME; | ||
| } | ||
| if (writerIp == null || writerIp.isBlank()) { | ||
| return ANONYMOUS_NAME; | ||
| } | ||
|
|
||
| String[] ip = writerIp.split("\\."); | ||
| String shortIp = (ip.length >= 2) ? ip[0] + "." + ip[1] : writerIp; | ||
| return ANONYMOUS_NAME + "(" + shortIp + ")"; | ||
| } | ||
| } | ||
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
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.