-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 댓글 작성 api 개발 #101
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
[feat] 댓글 작성 api 개발 #101
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7bdfd23
[remove] 더미파일 삭제(#97)
hd0rable 18fdd7f
[feat] Comment 도메인 생성 책임 코드 추가 (#97)
hd0rable e07ccf6
[feat] CommentCommandController.createComment 작성 (#97)
hd0rable e832743
[feat] CommentCommandPersistenceAdapter.save / findById 작성 (#97)
hd0rable 5e482df
[feat] CommentCommandPort 관련 함수 추가 작성 (#97)
hd0rable 3b9b5d5
[feat] CommentCountUpdatable작성 (#97)
hd0rable a264cda
[feat] 댓글 생성 Command dto 작성 (#97)
hd0rable 3a55c36
[feat] 댓글 생성 request dto 작성 (#97)
hd0rable 81ff6ca
[feat] 댓글 생성 유즈케이스 구현체 CommentCreateService 작성 (#97)
hd0rable 7c40758
[feat] 댓글 생성 유즈케이스 CommentCreateUseCase 작성 (#97)
hd0rable c189a0f
[feat] CommentIdResponse dto 작성 (#97)
hd0rable 2fa454a
[feat] CommentJpaEntity에 postType,likeCount 추가 (#97)
hd0rable 03fee58
[feat] CommentMapper 에 likeCount,postType 매핑추가 (#97)
hd0rable 567c537
[feat] 관련 에러코드 추가 (#97)
hd0rable d6cb099
[feat] vote,record, feed CommentCountUpdatableincreaseCommentCount공통 …
hd0rable 954f9d7
[feat] RecordCommandPersistenceAdapter.findById / update 작성 (#97)
hd0rable 376be34
[feat] VoteCommandPersistenceAdapter.findById / updateVote 작성 (#97)
hd0rable ee6addf
[feat] RecordCommandPort 관련 함수 추가 (#97)
hd0rable 8351056
[feat] VoteCommandPort 관련 함수 정의 (#97)
hd0rable 6b6293d
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable 1bde1e6
[feat] VoteJpaEntity.updateFrom 추가 (#97)
hd0rable be08e43
[feat] PostType enum 작성 (#97)
hd0rable c704fe8
[remove] 안쓰는 함수 삭제 (#97)
hd0rable b1d1387
[test] 댓글 생성 단위 테스트코드 작성 (#97)
hd0rable 0f90c97
[test] 댓글 생성 통합 테스트코드 작성 (#97)
hd0rable 5c5e2e9
[test] Comment 도메인 단위 테스트 코드 작성 (#97)
hd0rable f09f794
[test] 테스트펙토리 메서드 누락 값 추가 (#97)
hd0rable 2c01377
[test] 메서드 명 수정 (#97)
hd0rable a0c62cb
[test] postId 하드 코딩 수정 (#97)
hd0rable 9dfe2d0
[refactor] todo 주석 수정(#97)
hd0rable 4e77647
[fix] 누락 어노테이션 추가 (#97)
hd0rable 2eacfd8
[test] 테스트 코드 수정 (#97)
hd0rable 7c1249f
[refactor]RoomParticipantService 도메인 서비스 (#97)
hd0rable 3d680a5
[refactor]validateCreateComment 검증 추가 (#97)
hd0rable 770b6f2
[refactor] 관련 에러코드 수정및 추가(#97)
hd0rable 4f7b632
[refactor] 댓글 생성시 권한 검증 로직 추가(#97)
hd0rable f438ba6
[refactor] CommentCountUpdatable.getRoomId 추가 (#97)
hd0rable 791fee4
[test] 테스트마다 독립성 보장 어노테이션 추가 (#97)
hd0rable 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
23 changes: 22 additions & 1 deletion
23
src/main/java/konkuk/thip/comment/adapter/in/web/CommentCommandController.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,10 +1,31 @@ | ||
| package konkuk.thip.comment.adapter.in.web; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import konkuk.thip.comment.adapter.in.web.request.CommentCreateRequest; | ||
| import konkuk.thip.comment.adapter.in.web.response.CommentIdResponse; | ||
| import konkuk.thip.comment.application.port.in.CommentCreateUseCase; | ||
| import konkuk.thip.common.dto.BaseResponse; | ||
| import konkuk.thip.common.security.annotation.UserId; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class CommentCommandController { | ||
|
|
||
| private final CommentCreateUseCase commentCreateUseCase; | ||
|
|
||
|
|
||
| /** | ||
| * 댓글/답글 작성 | ||
| * parentId:{Long},isReplyRequest:true 답글 | ||
| * parentId:null,isReplyRequest:false 댓글 | ||
| */ | ||
| @PostMapping("/comments/{postId}") | ||
| public BaseResponse<CommentIdResponse> createComment(@RequestBody @Valid final CommentCreateRequest request, | ||
| @PathVariable("postId") final Long postId, | ||
| @UserId final Long userId) { | ||
| return BaseResponse.ok(CommentIdResponse.of(commentCreateUseCase.createComment(request.toCommand(userId,postId)))); | ||
| } | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/konkuk/thip/comment/adapter/in/web/request/CommentCreateRequest.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,31 @@ | ||
| package konkuk.thip.comment.adapter.in.web.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import konkuk.thip.comment.application.port.in.dto.CommentCreateCommand; | ||
|
|
||
| public record CommentCreateRequest( | ||
|
|
||
| @NotBlank(message = "댓글 내용은 필수입니다.") | ||
| String content, | ||
|
|
||
| @NotNull(message = "답글 여부는 필수입니다.") | ||
| Boolean isReplyRequest, | ||
|
|
||
| Long parentId, | ||
|
|
||
| @NotBlank(message = "게시물 타입은 필수입니다.") | ||
| String postType | ||
|
|
||
| ) { | ||
| public CommentCreateCommand toCommand(Long userId, Long postId) { | ||
| return new CommentCreateCommand( | ||
| content, | ||
| isReplyRequest, | ||
| parentId, | ||
| postType, | ||
| postId, | ||
| userId | ||
| ); | ||
| } | ||
| } |
7 changes: 0 additions & 7 deletions
7
src/main/java/konkuk/thip/comment/adapter/in/web/request/DummyRequest.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/java/konkuk/thip/comment/adapter/in/web/response/CommentIdResponse.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,7 @@ | ||
| package konkuk.thip.comment.adapter.in.web.response; | ||
|
|
||
| public record CommentIdResponse(Long commentId) { | ||
| public static CommentIdResponse of(Long commentId) { | ||
| return new CommentIdResponse(commentId); | ||
| } | ||
| } |
7 changes: 0 additions & 7 deletions
7
src/main/java/konkuk/thip/comment/adapter/in/web/response/DummyResponse.java
This file was deleted.
Oops, something went wrong.
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
62 changes: 62 additions & 0 deletions
62
...in/java/konkuk/thip/comment/adapter/out/persistence/CommentCommandPersistenceAdapter.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,12 +1,74 @@ | ||
| package konkuk.thip.comment.adapter.out.persistence; | ||
|
|
||
| import konkuk.thip.comment.adapter.out.jpa.CommentJpaEntity; | ||
| import konkuk.thip.comment.adapter.out.mapper.CommentMapper; | ||
| import konkuk.thip.comment.adapter.out.persistence.repository.CommentJpaRepository; | ||
| import konkuk.thip.comment.application.port.out.CommentCommandPort; | ||
| import konkuk.thip.comment.domain.Comment; | ||
| import konkuk.thip.common.exception.EntityNotFoundException; | ||
| import konkuk.thip.common.post.PostType; | ||
| import konkuk.thip.feed.adapter.out.persistence.repository.FeedJpaRepository; | ||
| import konkuk.thip.post.adapter.out.jpa.PostJpaEntity; | ||
| import konkuk.thip.record.adapter.out.persistence.repository.RecordJpaRepository; | ||
| import konkuk.thip.user.adapter.out.jpa.UserJpaEntity; | ||
| import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository; | ||
| import konkuk.thip.vote.adapter.out.persistence.repository.VoteJpaRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.*; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class CommentCommandPersistenceAdapter implements CommentCommandPort { | ||
|
|
||
| private final CommentJpaRepository commentJpaRepository; | ||
| private final FeedJpaRepository feedJpaRepository; | ||
| private final RecordJpaRepository recordJpaRepository; | ||
| private final VoteJpaRepository voteJpaRepository; | ||
| private final UserJpaRepository userJpaRepository; | ||
| private final CommentMapper commentMapper; | ||
|
|
||
| @Override | ||
| public Long save(Comment comment) { | ||
|
|
||
| // 1. 작성자(User) 조회 및 존재 검증 | ||
| UserJpaEntity userJpaEntity = userJpaRepository.findById(comment.getCreatorId()).orElseThrow( | ||
| () -> new EntityNotFoundException(USER_NOT_FOUND) | ||
| ); | ||
|
|
||
| // 2. 게시물(Post) 조회 및 존재 검증 | ||
| PostJpaEntity postJpaEntity = findPostJpaEntity(comment.getPostType(), comment.getTargetPostId()); | ||
|
|
||
| // 3. 부모 댓글 조회 (있을 경우) | ||
| CommentJpaEntity parentCommentJpaEntity = null; | ||
| if (comment.getParentCommentId() != null) { | ||
| parentCommentJpaEntity = commentJpaRepository.findById(comment.getParentCommentId()) | ||
| .orElseThrow(() -> new EntityNotFoundException(COMMENT_NOT_FOUND)); | ||
| } | ||
|
|
||
| return commentJpaRepository.save( | ||
| commentMapper.toJpaEntity(comment, postJpaEntity, userJpaEntity,parentCommentJpaEntity) | ||
| ).getCommentId(); | ||
| } | ||
|
|
||
| private PostJpaEntity findPostJpaEntity(PostType postType, Long postId) { | ||
| return switch (postType) { | ||
| case FEED -> feedJpaRepository.findById(postId) | ||
| .orElseThrow(() -> new EntityNotFoundException(FEED_NOT_FOUND)); | ||
| case RECORD -> recordJpaRepository.findById(postId) | ||
| .orElseThrow(() -> new EntityNotFoundException(RECORD_NOT_FOUND)); | ||
| case VOTE -> voteJpaRepository.findById(postId) | ||
| .orElseThrow(() -> new EntityNotFoundException(VOTE_NOT_FOUND)); | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Comment> findById(Long id) { | ||
| return commentJpaRepository.findById(id) | ||
| .map(commentMapper::toDomainEntity); | ||
| } | ||
|
Comment on lines
+34
to
+72
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
|
|
||
| } | ||
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
7 changes: 7 additions & 0 deletions
7
src/main/java/konkuk/thip/comment/application/port/in/CommentCreateUseCase.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,7 @@ | ||
| package konkuk.thip.comment.application.port.in; | ||
|
|
||
| import konkuk.thip.comment.application.port.in.dto.CommentCreateCommand; | ||
|
|
||
| public interface CommentCreateUseCase { | ||
| Long createComment(CommentCreateCommand command); | ||
| } |
5 changes: 0 additions & 5 deletions
5
src/main/java/konkuk/thip/comment/application/port/in/DummyUseCase.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/konkuk/thip/comment/application/port/in/dto/CommentCreateCommand.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,18 @@ | ||
| package konkuk.thip.comment.application.port.in.dto; | ||
|
|
||
| public record CommentCreateCommand( | ||
|
|
||
| String content, | ||
|
|
||
| Boolean isReplyRequest, | ||
|
|
||
| Long parentId, | ||
|
|
||
| String postType, | ||
|
|
||
| Long postId, | ||
|
|
||
| Long userId | ||
| ) | ||
| { | ||
| } |
10 changes: 0 additions & 10 deletions
10
src/main/java/konkuk/thip/comment/application/port/in/dto/DummyCommand.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/main/java/konkuk/thip/comment/application/port/out/CommentCommandPort.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,6 +1,22 @@ | ||
| package konkuk.thip.comment.application.port.out; | ||
|
|
||
|
|
||
| import konkuk.thip.comment.domain.Comment; | ||
| import konkuk.thip.common.exception.EntityNotFoundException; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.COMMENT_NOT_FOUND; | ||
|
|
||
| public interface CommentCommandPort { | ||
|
|
||
| Long save(Comment comment); | ||
|
|
||
| Optional<Comment> findById(Long id); | ||
|
|
||
| default Comment getByIdOrThrow(Long id) { | ||
| return findById(id) | ||
| .orElseThrow(() -> new EntityNotFoundException(COMMENT_NOT_FOUND)); | ||
| } | ||
|
|
||
| } |
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 |
|---|---|---|
|
|
@@ -2,6 +2,4 @@ | |
|
|
||
| public interface CommentQueryPort { | ||
|
|
||
| int countByPostId(Long postId); | ||
|
|
||
| } | ||
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.
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.
상속 구조 해지하더라도, comment가 어떤 PostJpaEntity(= 도메인 상에서는 Feed, Vote, Record) 와 연관되어 있는지를 알아야 하므로, CommentJpaEntity 는
private PostJpaEntity targetPostJpaEntity;
private PostType targetPostType:
을 가지고 있으면 되지 않을까요??
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.
음 제가 구현할때 Feed, Vote, Record가 다른 테이블구조로 리펙된다고 생각했을때 적은 TODO라 그런것같습니당