-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#35 - Feed/FeedComment CQRS 적용 #37
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
31 commits
Select commit
Hold shift + click to select a range
d8345fa
refactor: Feed 폴더 구조 변경
jbh010204 d75eae2
feat: FeedService를 command와 query로 분리
jbh010204 291ae9a
refactor: feed 도메인 내 어그레이트 약한 참조 관계로 변경
jbh010204 b30480a
refactor: Feed관련 DTO에서 사용하지 않는 메서드 삭제
jbh010204 7553103
refactor: Feed수정에 맞춰 테스트 변경
jbh010204 eb862fa
feat: FeedComment 약결합 분리 및 CQRS 패턴으로 변경
jbh010204 deec9d0
feat: FeedCommand 포트 확장
jbh010204 f80d05c
feat: FeedCommand 도메인 + 서비스 CQRS 분리
jbh010204 4a37258
feat: 댓글 조회시 필요한 유저 정보를 위해 UserData 포트/어댑터 추가
jbh010204 4179e1e
refactor: Feed와 FeedComment 느슨한 형태로 분리
jbh010204 76b8763
refactor: FeedResult 폴더 구조 Command의 DTO 위치로 변경
jbh010204 4b37f15
refactor: FeedQueryService 불필요한 트랜잭션 어노테이션 제거
jbh010204 f5971ef
feat: UserSnapshot DTO renamed to UserSnapShot and updated references
jbh010204 fb40dd7
refactor: FeedComment의 comment필드를 content로 명칭변경
jbh010204 ff62a4e
feat: rename FeedComment Aggregate to Comment
jbh010204 af6d726
feat: Feed 수정&삭제 기능 구현
jbh010204 0a43147
feat: Feed 통합 테스트 구현 및 단위 테스트 command용으로 분리
jbh010204 6065adb
Merge remote-tracking branch 'origin/develop' into feat/#35
jbh010204 fb1caef
docs: Feed 및 Comment Swaggeer 작성
jbh010204 7926140
refactor: test내부 클래스 stub 외부로 구조 변경
jbh010204 e7eebd9
refactor: User와 Profile 간접 참조 형태로 분리 및 연관된 코드 변경
jbh010204 d3a9022
feat: Replace UserDataPort with ProfileDataPort for user profile hand…
jbh010204 4367844
refactor: Rename entity from 'feed_comments' to 'comments' for clarity
jbh010204 c6aa091
refactor: ProfileSnapShot domain 패키지 구조로 이동
jbh010204 79cdea3
Merge remote-tracking branch 'origin/develop' into feat/#35
jbh010204 a37f38d
refactor: 피드 검증을 위한 FeedValidationPort and adapter 도입
jbh010204 2a54f69
refactor: author validation in Feed 도메인 내부 로직으로 변경
jbh010204 f2d6792
refactor: DB 스키마 변경에 따른 SQL feed_comments to comments 으로 변경
jbh010204 43a92c5
refactor: validation adapters의 스테레오타입을 Component로 변경
jbh010204 44ba7dd
refactor: ProfileJpaRepository 추가 및 프로필 저장 로직 구현
jbh010204 94e485b
fix : comments 객체와 다르게 구성된 sql문 수정
polyglot-k 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
Empty file.
52 changes: 52 additions & 0 deletions
52
src/main/java/com/example/bak/comment/application/command/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,52 @@ | ||
| package com.example.bak.comment.application.command; | ||
|
|
||
| import com.example.bak.comment.application.command.port.CommentCommandPort; | ||
| import com.example.bak.comment.application.command.port.ProfileDataPort; | ||
| import com.example.bak.comment.domain.Comment; | ||
| import com.example.bak.comment.domain.ProfileSnapShot; | ||
| import com.example.bak.feed.application.command.port.FeedValidationPort; | ||
| import com.example.bak.global.exception.BusinessException; | ||
| import com.example.bak.global.exception.ErrorCode; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class CommentCommandService { | ||
|
|
||
| private final CommentCommandPort commentCommandPort; | ||
| private final FeedValidationPort feedValidationPort; | ||
| private final ProfileDataPort profileDataPort; | ||
|
|
||
| public void createComment(Long feedId, String content, Long userId) { | ||
| if (!feedValidationPort.existsById(feedId)) { | ||
| throw new BusinessException(ErrorCode.FEED_NOT_FOUND); | ||
| } | ||
|
|
||
| ProfileSnapShot userProfile = profileDataPort.findSnapshotByUserId(userId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.USER_NOT_FOUND)); | ||
|
|
||
| Comment newComment = Comment.create( | ||
| feedId, | ||
| content, | ||
| userProfile.userId(), | ||
| userProfile.nickname() | ||
| ); | ||
|
|
||
| commentCommandPort.save(newComment); | ||
| } | ||
|
|
||
| public void updateComment(Long commentId, String content, Long userId) { | ||
| Comment comment = commentCommandPort.findById(commentId) | ||
| .orElseThrow(() -> new BusinessException(ErrorCode.COMMENT_NOT_FOUND)); | ||
|
|
||
| if (!comment.isWrittenBy(userId)) { | ||
| throw new BusinessException(ErrorCode.UNAUTHORIZED_ACTION); | ||
| } | ||
|
|
||
| comment.updateComment(content); | ||
| commentCommandPort.save(comment); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/bak/comment/application/command/port/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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.example.bak.comment.application.command.port; | ||
|
|
||
| import com.example.bak.comment.domain.Comment; | ||
| import java.util.Optional; | ||
|
|
||
| public interface CommentCommandPort { | ||
|
|
||
| Comment save(Comment comment); | ||
|
|
||
| Optional<Comment> findById(Long commentId); | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/bak/comment/application/command/port/ProfileDataPort.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,9 @@ | ||
| package com.example.bak.comment.application.command.port; | ||
|
|
||
| import com.example.bak.comment.domain.ProfileSnapShot; | ||
| import java.util.Optional; | ||
|
|
||
| public interface ProfileDataPort { | ||
|
|
||
| Optional<ProfileSnapShot> findSnapshotByUserId(Long userId); | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/bak/comment/application/query/CommentQueryService.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,20 @@ | ||
| package com.example.bak.comment.application.query; | ||
|
|
||
| import com.example.bak.comment.application.query.dto.CommentInfo; | ||
| import com.example.bak.comment.application.query.port.CommentQueryPort; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class CommentQueryService { | ||
|
|
||
| private final CommentQueryPort commentQueryPort; | ||
|
|
||
| public List<CommentInfo> getComments(Long feedId) { | ||
| return commentQueryPort.findByFeedId(feedId); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/bak/comment/application/query/dto/CommentInfo.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,23 @@ | ||
| package com.example.bak.comment.application.query.dto; | ||
|
|
||
| import com.example.bak.comment.domain.Comment; | ||
|
|
||
| /** | ||
| * Comment의 기본 정보를 담는 DTO Feed 상세 조회 시 포함됨 | ||
| */ | ||
| public record CommentInfo( | ||
| Long id, | ||
| Long authorId, | ||
| String authorName, | ||
| String content | ||
| ) { | ||
|
|
||
| public static CommentInfo from(Comment comment) { | ||
| return new CommentInfo( | ||
| comment.getId(), | ||
| comment.getAuthorId(), | ||
| comment.getAuthorNickname(), | ||
| comment.getContent() | ||
| ); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/bak/comment/application/query/port/CommentQueryPort.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,9 @@ | ||
| package com.example.bak.comment.application.query.port; | ||
|
|
||
| import com.example.bak.comment.application.query.dto.CommentInfo; | ||
| import java.util.List; | ||
|
|
||
| public interface CommentQueryPort { | ||
|
|
||
| List<CommentInfo> findByFeedId(Long feedId); | ||
| } |
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,69 @@ | ||
| package com.example.bak.comment.domain; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import java.util.Objects; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity(name = "comments") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Comment { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "feed_id", nullable = false) | ||
| private Long feedId; | ||
|
|
||
| @Column(nullable = false) | ||
| private Long authorId; | ||
|
|
||
| @Column(nullable = false) | ||
| private String authorNickname; | ||
|
|
||
| @Column(nullable = false) | ||
| private String content; | ||
|
|
||
| private Comment(Long id, Long feedId, String content, Long authorId, | ||
| String authorNickname) { | ||
| this.id = id; | ||
| this.feedId = feedId; | ||
| this.content = content; | ||
| this.authorId = authorId; | ||
| this.authorNickname = authorNickname; | ||
| } | ||
|
|
||
| private Comment(Long feedId, String content, Long authorId, String authorNickname) { | ||
| this.feedId = feedId; | ||
| this.content = content; | ||
| this.authorId = authorId; | ||
| this.authorNickname = authorNickname; | ||
| } | ||
|
|
||
| public static Comment create(Long feedId, String comment, Long authorId, | ||
| String authorNickname) { | ||
| return new Comment(feedId, comment, authorId, authorNickname); | ||
| } | ||
|
|
||
| public static Comment testInstance(Long id, Long feedId, String comment, Long authorId, | ||
| String authorNickname) { | ||
| return new Comment(id, feedId, comment, authorId, authorNickname); | ||
| } | ||
|
|
||
| public void updateComment(String comment) { | ||
| this.content = comment; | ||
| } | ||
|
|
||
| public boolean isWrittenBy(Long authorId) { | ||
| return Objects.equals(this.authorId, authorId); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/example/bak/comment/domain/ProfileSnapShot.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.example.bak.comment.domain; | ||
|
|
||
| public record ProfileSnapShot(Long userId, String nickname) { | ||
|
|
||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/example/bak/comment/infra/persistence/CommentCommandAdapter.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,24 @@ | ||
| package com.example.bak.comment.infra.persistence; | ||
|
|
||
| import com.example.bak.comment.application.command.port.CommentCommandPort; | ||
| import com.example.bak.comment.domain.Comment; | ||
| import java.util.Optional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class CommentCommandAdapter implements CommentCommandPort { | ||
|
|
||
| private final CommentJpaRepository commentJpaRepository; | ||
|
|
||
| @Override | ||
| public Comment save(Comment comment) { | ||
| return commentJpaRepository.save(comment); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Comment> findById(Long commentId) { | ||
| return commentJpaRepository.findById(commentId); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/bak/comment/infra/persistence/CommentJpaRepository.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.example.bak.comment.infra.persistence; | ||
|
|
||
| import com.example.bak.comment.domain.Comment; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CommentJpaRepository extends JpaRepository<Comment, Long> { | ||
|
|
||
| List<Comment> findByFeedId(Long feedId); | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/bak/comment/infra/persistence/CommentQueryAdapter.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,21 @@ | ||
| package com.example.bak.comment.infra.persistence; | ||
|
|
||
| import com.example.bak.comment.application.query.dto.CommentInfo; | ||
| import com.example.bak.comment.application.query.port.CommentQueryPort; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class CommentQueryAdapter implements CommentQueryPort { | ||
|
|
||
| private final CommentJpaRepository commentJpaRepository; | ||
|
|
||
| @Override | ||
| public List<CommentInfo> findByFeedId(Long feedId) { | ||
| return commentJpaRepository.findByFeedId(feedId).stream() | ||
| .map(CommentInfo::from) | ||
| .toList(); | ||
| } | ||
| } |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/example/bak/comment/presentation/dto/CommentRequest.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.example.bak.comment.presentation.dto; | ||
|
|
||
| public record CommentRequest(String content) { | ||
|
|
||
| } |
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.