From 9e63c1232c1fbfef2bcc8611dda7841479693af0 Mon Sep 17 00:00:00 2001 From: Donghun Shin Date: Tue, 28 Nov 2023 04:03:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B8=B0=EC=A1=B4=20PostId=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20Blog=EB=B3=84=EB=A1=9C=20PostId=EB=A5=BC=20?= =?UTF-8?q?=EA=B0=96=EB=8F=84=EB=A1=9D=20=EB=B3=B5=ED=95=A9=ED=82=A4?= =?UTF-8?q?=EB=A1=9C=20=EC=84=A4=EC=A0=95=20(#103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/AuthCommentService.java | 4 +- .../application/UnAuthCommentService.java | 4 +- .../command/WriteAuthCommentCommand.java | 1 + .../command/WriteUnAuthCommentCommand.java | 1 + .../com/mallang/comment/domain/Comment.java | 6 +- .../comment/domain/CommentRepository.java | 13 +- .../presentation/CommentController.java | 5 +- .../request/WriteAuthCommentRequest.java | 2 + .../request/WriteUnAuthCommentRequest.java | 2 + .../query/CommentDataPostProcessor.java | 11 +- .../comment/query/CommentDataValidator.java | 3 +- .../comment/query/CommentQueryService.java | 13 +- .../mallang/comment/query/dao/CommentDao.java | 5 +- .../query/supoort/CommentQuerySupport.java | 5 +- .../mallang/common/domain/DomainEvent.java | 2 +- .../post/application/PostLikeService.java | 5 +- .../mallang/post/application/PostService.java | 17 ++- .../post/application/PostStarService.java | 5 +- .../command/CancelPostLikeCommand.java | 1 + .../command/CancelPostStarCommand.java | 3 +- .../command/ClickPostLikeCommand.java | 1 + .../command/CreatePostCommand.java | 11 +- .../command/DeletePostCommand.java | 3 +- .../application/command/StarPostCommand.java | 1 + .../command/UpdatePostCommand.java | 3 +- .../java/com/mallang/post/domain/Post.java | 85 ++++++----- .../mallang/post/domain/PostDeleteEvent.java | 6 +- .../java/com/mallang/post/domain/PostId.java | 44 ++++++ .../post/domain/PostOrderInBlogGenerator.java | 6 +- .../mallang/post/domain/PostRepository.java | 31 ++-- .../PostVisibilityPolicy.java | 2 +- .../java/com/mallang/post/domain/Tag.java | 18 ++- .../mallang/post/domain/like/PostLike.java | 6 +- .../post/domain/like/PostLikeRepository.java | 19 ++- .../mallang/post/domain/star/PostStar.java | 6 +- .../post/domain/star/PostStarRepository.java | 19 ++- .../post/presentation/PostController.java | 7 +- .../presentation/PostManageController.java | 11 +- .../request/CancelPostLikeRequest.java | 5 +- .../request/CancelPostStarRequest.java | 5 +- .../request/ClickPostLikeRequest.java | 5 +- .../request/CreatePostRequest.java | 2 +- .../request/DeletePostRequest.java | 5 +- .../presentation/request/StarPostRequest.java | 5 +- .../request/UpdatePostRequest.java | 4 +- .../mallang/post/query/PostDataProtector.java | 5 +- .../mallang/post/query/PostDataValidator.java | 2 +- .../post/query/PostManageQueryService.java | 4 +- .../mallang/post/query/PostQueryService.java | 9 +- .../mallang/post/query/dao/PostDetailDao.java | 8 +- .../post/query/dao/PostManageDetailDao.java | 5 +- .../post/query/dao/PostManageSearchDao.java | 4 +- .../mallang/post/query/dao/PostSearchDao.java | 6 +- .../mallang/post/query/dao/StaredPostDao.java | 2 +- .../query/response/PostDetailResponse.java | 6 +- .../response/PostManageDetailResponse.java | 4 +- .../response/PostManageSearchResponse.java | 4 +- .../query/response/PostSearchResponse.java | 6 +- .../query/response/StaredPostResponse.java | 6 +- .../query/support/PostLikeQuerySupport.java | 16 ++- .../post/query/support/PostQuerySupport.java | 27 +++- .../collector/PostViewHistoryAop.java | 6 +- .../category/CategoryAcceptanceTest.java | 5 +- .../comment/CommentAcceptanceSteps.java | 5 +- .../comment/CommentAcceptanceTest.java | 136 +++++++++--------- .../acceptance/post/PostAcceptanceSteps.java | 3 +- .../acceptance/post/PostAcceptanceTest.java | 31 ++-- .../post/PostLikeAcceptanceSteps.java | 18 ++- .../post/PostLikeAcceptanceTest.java | 50 +++---- .../post/PostManageAcceptanceSteps.java | 16 +-- .../post/PostManageAcceptanceTest.java | 47 ++---- .../post/PostStarAcceptanceSteps.java | 9 +- .../post/PostStarAcceptanceTest.java | 70 ++++----- .../blog/application/AboutServiceTest.java | 22 ++- .../application/BlogSubscribeServiceTest.java | 24 +++- .../com/mallang/blog/domain/AboutTest.java | 10 +- .../com/mallang/blog/domain/BlogFixture.java | 22 +++ .../com/mallang/blog/domain/BlogTest.java | 8 +- .../domain/subscribe/BlogSubscribeTest.java | 7 +- .../subscribe/BlogSubscribeValidatorTest.java | 7 +- .../application/CommentEventHandlerTest.java | 19 +-- .../application/CommentServiceTest.java | 78 +++++----- .../comment/domain/AuthCommentTest.java | 15 +- .../mallang/comment/domain/CommentTest.java | 5 +- .../comment/domain/UnAuthCommentTest.java | 15 +- .../service/CommentDeleteServiceTest.java | 5 +- .../query/CommentQueryServiceTest.java | 35 ++--- .../CommentResponsePostProcessorTest.java | 16 ++- .../query/CommentResponseValidatorTest.java | 35 +++-- .../java/com/mallang/common/ServiceTest.java | 60 +++++--- .../application/PostEventHandlerTest.java | 12 +- .../application/PostLikeEventHandlerTest.java | 8 +- .../post/application/PostLikeServiceTest.java | 81 ++++++----- .../post/application/PostServiceTest.java | 76 +++++----- .../application/PostStarEventHandlerTest.java | 8 +- .../post/application/PostStarServiceTest.java | 51 +++---- .../com/mallang/post/domain/PostIdTest.java | 31 ++++ .../domain/PostOrderInBlogGeneratorTest.java | 9 +- .../com/mallang/post/domain/PostTest.java | 41 +++--- .../post/domain/like/PostLikeTest.java | 14 +- .../domain/like/PostLikeValidatorTest.java | 1 - .../domain/star/PostStarValidatorTest.java | 1 - .../visibility/PostVisibilityPolicyTest.java | 3 +- .../post/query/PostDataProtectorTest.java | 8 +- .../post/query/PostDataValidatorTest.java | 2 +- .../post/query/PostQueryServiceTest.java | 104 +++++++------- .../post/query/PostStarQueryServiceTest.java | 47 +++--- .../post/query/dao/PostSearchDaoTest.java | 16 +-- .../collector/PostViewHistoryAopTest.java | 34 ++--- 109 files changed, 1078 insertions(+), 780 deletions(-) create mode 100644 src/main/java/com/mallang/post/domain/PostId.java rename src/main/java/com/mallang/post/domain/{visibility => }/PostVisibilityPolicy.java (97%) create mode 100644 src/test/java/com/mallang/blog/domain/BlogFixture.java create mode 100644 src/test/java/com/mallang/post/domain/PostIdTest.java diff --git a/src/main/java/com/mallang/comment/application/AuthCommentService.java b/src/main/java/com/mallang/comment/application/AuthCommentService.java index 8139fcbc..7f8ce53d 100644 --- a/src/main/java/com/mallang/comment/application/AuthCommentService.java +++ b/src/main/java/com/mallang/comment/application/AuthCommentService.java @@ -26,9 +26,9 @@ public class AuthCommentService { private final CommentDeleteService commentDeleteService; public Long write(WriteAuthCommentCommand command) { - Post post = postRepository.getById(command.postId()); + Post post = postRepository.getByIdAndBlogName(command.postId(), command.blogName()); Member writer = memberRepository.getById(command.memberId()); - Comment parent = commentRepository.getParentByIdAndPostId(command.parentCommentId(), command.postId()); + Comment parent = commentRepository.getParentByIdAndPost(command.parentCommentId(), post); AuthComment comment = command.toComment(post, writer, parent); comment.write(command.postPassword()); return commentRepository.save(comment).getId(); diff --git a/src/main/java/com/mallang/comment/application/UnAuthCommentService.java b/src/main/java/com/mallang/comment/application/UnAuthCommentService.java index 8c09fad8..0a28dca0 100644 --- a/src/main/java/com/mallang/comment/application/UnAuthCommentService.java +++ b/src/main/java/com/mallang/comment/application/UnAuthCommentService.java @@ -26,8 +26,8 @@ public class UnAuthCommentService { private final CommentDeleteService commentDeleteService; public Long write(WriteUnAuthCommentCommand command) { - Post post = postRepository.getById(command.postId()); - Comment parent = commentRepository.getParentByIdAndPostId(command.parentCommentId(), command.postId()); + Post post = postRepository.getByIdAndBlogName(command.postId(), command.blogName()); + Comment parent = commentRepository.getParentByIdAndPost(command.parentCommentId(), post); UnAuthComment comment = command.toCommand(post, parent); comment.write(command.postPassword()); return commentRepository.save(comment).getId(); diff --git a/src/main/java/com/mallang/comment/application/command/WriteAuthCommentCommand.java b/src/main/java/com/mallang/comment/application/command/WriteAuthCommentCommand.java index b7d637eb..65403edd 100644 --- a/src/main/java/com/mallang/comment/application/command/WriteAuthCommentCommand.java +++ b/src/main/java/com/mallang/comment/application/command/WriteAuthCommentCommand.java @@ -10,6 +10,7 @@ @Builder public record WriteAuthCommentCommand( Long postId, + String blogName, String content, boolean secret, Long memberId, diff --git a/src/main/java/com/mallang/comment/application/command/WriteUnAuthCommentCommand.java b/src/main/java/com/mallang/comment/application/command/WriteUnAuthCommentCommand.java index d7619c80..7f6ce526 100644 --- a/src/main/java/com/mallang/comment/application/command/WriteUnAuthCommentCommand.java +++ b/src/main/java/com/mallang/comment/application/command/WriteUnAuthCommentCommand.java @@ -9,6 +9,7 @@ @Builder public record WriteUnAuthCommentCommand( Long postId, + String blogName, String content, String nickname, String password, diff --git a/src/main/java/com/mallang/comment/domain/Comment.java b/src/main/java/com/mallang/comment/domain/Comment.java index 8df3878d..8865b195 100644 --- a/src/main/java/com/mallang/comment/domain/Comment.java +++ b/src/main/java/com/mallang/comment/domain/Comment.java @@ -16,6 +16,7 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinColumns; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import java.util.ArrayList; @@ -35,7 +36,10 @@ public abstract class Comment extends CommonDomainModel { protected String content; @ManyToOne(fetch = LAZY) - @JoinColumn(name = "post_id", nullable = false) + @JoinColumns({ + @JoinColumn(name = "post_id", referencedColumnName = "post_id"), + @JoinColumn(name = "blog_id", referencedColumnName = "blog_id"), + }) protected Post post; protected boolean deleted; diff --git a/src/main/java/com/mallang/comment/domain/CommentRepository.java b/src/main/java/com/mallang/comment/domain/CommentRepository.java index 289cd3ac..3cc63a9f 100644 --- a/src/main/java/com/mallang/comment/domain/CommentRepository.java +++ b/src/main/java/com/mallang/comment/domain/CommentRepository.java @@ -1,12 +1,15 @@ package com.mallang.comment.domain; import com.mallang.comment.exception.NotFoundCommentException; +import com.mallang.post.domain.Post; +import com.mallang.post.domain.PostId; import jakarta.annotation.Nullable; import java.util.Optional; import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface CommentRepository extends JpaRepository { @@ -27,17 +30,17 @@ default Comment getById(Long id) { @EntityGraph(attributePaths = {"parent"}) Optional findById(Long id); - default Comment getParentByIdAndPostId(@Nullable Long parentCommentId, Long postId) { + default Comment getParentByIdAndPost(@Nullable Long parentCommentId, Post post) { if (parentCommentId == null) { return null; } - return findByIdAndPostId(parentCommentId, postId) + return findByIdAndPost(parentCommentId, post) .orElseThrow(NotFoundCommentException::new); } - Optional findByIdAndPostId(Long id, Long postId); + Optional findByIdAndPost(Long id, Post post); @Modifying - @Query("DELETE FROM Comment c WHERE c.post.id = :postId") - void deleteAllByPostId(Long postId); + @Query("DELETE FROM Comment c WHERE c.post.postId = :postId") + void deleteAllByPostId(@Param("postId") PostId postId); } diff --git a/src/main/java/com/mallang/comment/presentation/CommentController.java b/src/main/java/com/mallang/comment/presentation/CommentController.java index bfa0f369..e852a496 100644 --- a/src/main/java/com/mallang/comment/presentation/CommentController.java +++ b/src/main/java/com/mallang/comment/presentation/CommentController.java @@ -74,9 +74,10 @@ public ResponseEntity delete( public ResponseEntity> findAll( @CookieValue(name = POST_PASSWORD_COOKIE, required = false) String postPassword, @Nullable @OptionalAuth Long memberId, - @RequestParam(value = "postId", required = true) Long postId + @RequestParam(value = "postId", required = true) Long postId, + @RequestParam(value = "blogName", required = true) String blogName ) { - List result = commentQueryService.findAllByPostId(postId, memberId, postPassword); + List result = commentQueryService.findAllByPost(postId, blogName, memberId, postPassword); return ResponseEntity.ok(result); } } diff --git a/src/main/java/com/mallang/comment/presentation/request/WriteAuthCommentRequest.java b/src/main/java/com/mallang/comment/presentation/request/WriteAuthCommentRequest.java index c6ed6229..42fdef48 100644 --- a/src/main/java/com/mallang/comment/presentation/request/WriteAuthCommentRequest.java +++ b/src/main/java/com/mallang/comment/presentation/request/WriteAuthCommentRequest.java @@ -5,6 +5,7 @@ public record WriteAuthCommentRequest( Long postId, + String blogName, String content, boolean secret, @Nullable Long parentCommentId @@ -13,6 +14,7 @@ public record WriteAuthCommentRequest( public WriteAuthCommentCommand toCommand(Long memberId, @Nullable String postPassword) { return WriteAuthCommentCommand.builder() .postId(postId) + .blogName(blogName) .postPassword(postPassword) .content(content) .secret(secret) diff --git a/src/main/java/com/mallang/comment/presentation/request/WriteUnAuthCommentRequest.java b/src/main/java/com/mallang/comment/presentation/request/WriteUnAuthCommentRequest.java index 1e446e8d..c2b8a8a8 100644 --- a/src/main/java/com/mallang/comment/presentation/request/WriteUnAuthCommentRequest.java +++ b/src/main/java/com/mallang/comment/presentation/request/WriteUnAuthCommentRequest.java @@ -5,6 +5,7 @@ public record WriteUnAuthCommentRequest( Long postId, + String blogName, String content, String nickname, String password, @@ -14,6 +15,7 @@ public record WriteUnAuthCommentRequest( public WriteUnAuthCommentCommand toCommand(@Nullable String postPassword) { return WriteUnAuthCommentCommand.builder() .postId(postId) + .blogName(blogName) .postPassword(postPassword) .content(content) .nickname(nickname) diff --git a/src/main/java/com/mallang/comment/query/CommentDataPostProcessor.java b/src/main/java/com/mallang/comment/query/CommentDataPostProcessor.java index a4babc3d..bc92af80 100644 --- a/src/main/java/com/mallang/comment/query/CommentDataPostProcessor.java +++ b/src/main/java/com/mallang/comment/query/CommentDataPostProcessor.java @@ -51,8 +51,11 @@ private CommentResponse processDeleted(CommentResponse data) { .build(); } - public List processSecret(List datas, Long postId, @Nullable Long memberId) { - if (isPostWriter(postId, memberId)) { + public List processSecret(List datas, + Long postId, + String blogName, + @Nullable Long memberId) { + if (isPostWriter(postId, blogName, memberId)) { return datas; } return datas.stream() @@ -60,8 +63,8 @@ public List processSecret(List datas, Long pos .toList(); } - private boolean isPostWriter(Long postId, @Nullable Long memberId) { - Post post = postRepository.getById(postId); + private boolean isPostWriter(Long postId, String blogName, @Nullable Long memberId) { + Post post = postRepository.getByIdAndBlogName(postId, blogName); return Objects.equals(post.getWriter().getId(), memberId); } diff --git a/src/main/java/com/mallang/comment/query/CommentDataValidator.java b/src/main/java/com/mallang/comment/query/CommentDataValidator.java index d90ff975..520da531 100644 --- a/src/main/java/com/mallang/comment/query/CommentDataValidator.java +++ b/src/main/java/com/mallang/comment/query/CommentDataValidator.java @@ -16,9 +16,10 @@ public class CommentDataValidator { private final PostRepository postRepository; public void validateAccessPost(Long postId, + String blogName, @Nullable Long memberId, @Nullable String postPassword) { - Post post = postRepository.getById(postId); + Post post = postRepository.getByIdAndBlogName(postId, blogName); Member member = null; if (memberId != null) { member = memberRepository.getById(memberId); diff --git a/src/main/java/com/mallang/comment/query/CommentQueryService.java b/src/main/java/com/mallang/comment/query/CommentQueryService.java index 79ddcc97..93c36d82 100644 --- a/src/main/java/com/mallang/comment/query/CommentQueryService.java +++ b/src/main/java/com/mallang/comment/query/CommentQueryService.java @@ -17,12 +17,13 @@ public class CommentQueryService { private final CommentDataValidator commentDataValidator; private final CommentDataPostProcessor commentDataPostProcessor; - public List findAllByPostId(Long postId, - @Nullable Long memberId, - @Nullable String postPassword) { - commentDataValidator.validateAccessPost(postId, memberId, postPassword); - List result = commentDao.findAllByPostId(postId); + public List findAllByPost(Long postId, + String blogName, + @Nullable Long memberId, + @Nullable String postPassword) { + commentDataValidator.validateAccessPost(postId, blogName, memberId, postPassword); + List result = commentDao.findAllByPost(postId, blogName); List deletedProcessedResult = commentDataPostProcessor.processDeleted(result); - return commentDataPostProcessor.processSecret(deletedProcessedResult, postId, memberId); + return commentDataPostProcessor.processSecret(deletedProcessedResult, postId, blogName, memberId); } } diff --git a/src/main/java/com/mallang/comment/query/dao/CommentDao.java b/src/main/java/com/mallang/comment/query/dao/CommentDao.java index 60e9ab97..8a3031bf 100644 --- a/src/main/java/com/mallang/comment/query/dao/CommentDao.java +++ b/src/main/java/com/mallang/comment/query/dao/CommentDao.java @@ -15,8 +15,9 @@ public class CommentDao { private final CommentQuerySupport commentQuerySupport; - public List findAllByPostId(Long postId) { - return commentQuerySupport.findAllByPostId(postId).stream() + public List findAllByPost(Long postId, String blogName) { + return commentQuerySupport.findAllByPost(postId, blogName) + .stream() .filter(it -> Objects.isNull(it.getParent())) .map(CommentResponse::from) .toList(); diff --git a/src/main/java/com/mallang/comment/query/supoort/CommentQuerySupport.java b/src/main/java/com/mallang/comment/query/supoort/CommentQuerySupport.java index 3eebb3d8..46ee0e70 100644 --- a/src/main/java/com/mallang/comment/query/supoort/CommentQuerySupport.java +++ b/src/main/java/com/mallang/comment/query/supoort/CommentQuerySupport.java @@ -3,8 +3,11 @@ import com.mallang.comment.domain.Comment; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface CommentQuerySupport extends JpaRepository { - List findAllByPostId(Long postId); + @Query("SELECT c FROM Comment c WHERE c.post.postId.id = :postId AND c.post.blog.name.value = :blogName") + List findAllByPost(@Param("postId") Long postId, @Param("blogName") String blogName); } diff --git a/src/main/java/com/mallang/common/domain/DomainEvent.java b/src/main/java/com/mallang/common/domain/DomainEvent.java index 9e92ac38..4369900e 100644 --- a/src/main/java/com/mallang/common/domain/DomainEvent.java +++ b/src/main/java/com/mallang/common/domain/DomainEvent.java @@ -2,5 +2,5 @@ public interface DomainEvent { - Long id(); + Object id(); } diff --git a/src/main/java/com/mallang/post/application/PostLikeService.java b/src/main/java/com/mallang/post/application/PostLikeService.java index d7282616..5b1ab06b 100644 --- a/src/main/java/com/mallang/post/application/PostLikeService.java +++ b/src/main/java/com/mallang/post/application/PostLikeService.java @@ -24,7 +24,7 @@ public class PostLikeService { private final PostLikeValidator postLikeValidator; public void like(ClickPostLikeCommand command) { - Post post = postRepository.getById(command.postId()); + Post post = postRepository.getByIdAndBlogName(command.postId(), command.blogName()); Member member = memberRepository.getById(command.memberId()); PostLike postLike = new PostLike(post, member); postLike.like(postLikeValidator, command.postPassword()); @@ -32,7 +32,8 @@ public void like(ClickPostLikeCommand command) { } public void cancel(CancelPostLikeCommand command) { - PostLike postLike = postLikeRepository.getByPostIdAndMemberId(command.postId(), command.memberId()); + PostLike postLike = postLikeRepository + .getByPostIdAndMemberId(command.postId(), command.blogName(), command.memberId()); postLike.cancel(command.postPassword()); postLikeRepository.delete(postLike); } diff --git a/src/main/java/com/mallang/post/application/PostService.java b/src/main/java/com/mallang/post/application/PostService.java index 835ba8ea..6480267e 100644 --- a/src/main/java/com/mallang/post/application/PostService.java +++ b/src/main/java/com/mallang/post/application/PostService.java @@ -10,10 +10,11 @@ import com.mallang.post.application.command.DeletePostCommand; import com.mallang.post.application.command.UpdatePostCommand; import com.mallang.post.domain.Post; +import com.mallang.post.domain.PostId; import com.mallang.post.domain.PostIntro; import com.mallang.post.domain.PostOrderInBlogGenerator; import com.mallang.post.domain.PostRepository; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import jakarta.annotation.Nullable; import java.util.List; import lombok.RequiredArgsConstructor; @@ -31,17 +32,18 @@ public class PostService { private final CategoryRepository categoryRepository; private final PostOrderInBlogGenerator postOrderInBlogGenerator; - public Long create(CreatePostCommand command) { + public PostId create(CreatePostCommand command) { Member member = memberRepository.getById(command.memberId()); Blog blog = blogRepository.getByNameAndOwnerId(command.blogName(), command.memberId()); Category category = getCategoryByIdAndOwnerIdIfPresent(command.categoryId(), command.memberId()); - Long postId = postOrderInBlogGenerator.generate(blog); - Post post = command.toPost(member, blog, category, postId); - return postRepository.save(post).getId(); + PostId postId = postOrderInBlogGenerator.generate(blog.getId()); + Post post = command.toPost(member, category, postId); + return postRepository.save(post).getPostId(); } public void update(UpdatePostCommand command) { - Post post = postRepository.getByIdAndWriterId(command.postId(), command.memberId()); + Post post = postRepository + .getByIdAndBlogNameAndWriterId(command.postId(), command.blogName(), command.memberId()); Category category = getCategoryByIdAndOwnerIdIfPresent(command.categoryId(), command.memberId()); post.update( command.title(), @@ -55,7 +57,8 @@ public void update(UpdatePostCommand command) { } public void delete(DeletePostCommand command) { - List posts = postRepository.findAllByIdInAndWriterId(command.postIds(), command.memberId()); + List posts = postRepository + .findAllByIdInAndWriterId(command.postIds(), command.blogName(), command.memberId()); for (Post post : posts) { post.delete(); postRepository.delete(post); diff --git a/src/main/java/com/mallang/post/application/PostStarService.java b/src/main/java/com/mallang/post/application/PostStarService.java index d25e9fb4..3ccea916 100644 --- a/src/main/java/com/mallang/post/application/PostStarService.java +++ b/src/main/java/com/mallang/post/application/PostStarService.java @@ -24,7 +24,7 @@ public class PostStarService { private final PostStarValidator postStarValidator; public Long star(StarPostCommand command) { - Post post = postRepository.getById(command.postId()); + Post post = postRepository.getByIdAndBlogName(command.postId(), command.blogName()); Member member = memberRepository.getById(command.memberId()); PostStar postStar = new PostStar(post, member); postStar.star(postStarValidator, command.postPassword()); @@ -33,7 +33,8 @@ public Long star(StarPostCommand command) { } public void cancel(CancelPostStarCommand command) { - PostStar postStar = postStarRepository.getByPostIdAndMemberId(command.postId(), command.memberId()); + PostStar postStar = postStarRepository + .getByPostIdAndBlogNameAndMemberId(command.postId(), command.blogName(), command.memberId()); postStarRepository.delete(postStar); } } diff --git a/src/main/java/com/mallang/post/application/command/CancelPostLikeCommand.java b/src/main/java/com/mallang/post/application/command/CancelPostLikeCommand.java index bf191684..ccce1471 100644 --- a/src/main/java/com/mallang/post/application/command/CancelPostLikeCommand.java +++ b/src/main/java/com/mallang/post/application/command/CancelPostLikeCommand.java @@ -4,6 +4,7 @@ public record CancelPostLikeCommand( Long postId, + String blogName, Long memberId, @Nullable String postPassword ) { diff --git a/src/main/java/com/mallang/post/application/command/CancelPostStarCommand.java b/src/main/java/com/mallang/post/application/command/CancelPostStarCommand.java index deb0fd77..fd114cf3 100644 --- a/src/main/java/com/mallang/post/application/command/CancelPostStarCommand.java +++ b/src/main/java/com/mallang/post/application/command/CancelPostStarCommand.java @@ -1,7 +1,8 @@ package com.mallang.post.application.command; public record CancelPostStarCommand( + Long memberId, Long postId, - Long memberId + String blogName ) { } diff --git a/src/main/java/com/mallang/post/application/command/ClickPostLikeCommand.java b/src/main/java/com/mallang/post/application/command/ClickPostLikeCommand.java index 6fdbedca..84c2fbb1 100644 --- a/src/main/java/com/mallang/post/application/command/ClickPostLikeCommand.java +++ b/src/main/java/com/mallang/post/application/command/ClickPostLikeCommand.java @@ -4,6 +4,7 @@ public record ClickPostLikeCommand( Long postId, + String blogName, Long memberId, @Nullable String postPassword ) { diff --git a/src/main/java/com/mallang/post/application/command/CreatePostCommand.java b/src/main/java/com/mallang/post/application/command/CreatePostCommand.java index ebb2b78d..ebf9a744 100644 --- a/src/main/java/com/mallang/post/application/command/CreatePostCommand.java +++ b/src/main/java/com/mallang/post/application/command/CreatePostCommand.java @@ -1,12 +1,12 @@ package com.mallang.post.application.command; import com.mallang.auth.domain.Member; -import com.mallang.blog.domain.Blog; import com.mallang.category.domain.Category; import com.mallang.post.domain.Post; +import com.mallang.post.domain.PostId; import com.mallang.post.domain.PostIntro; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.util.List; import lombok.Builder; @@ -24,13 +24,12 @@ public record CreatePostCommand( @Nullable Long categoryId, List tags ) { - public Post toPost(Member member, Blog blog, Category category, Long postIdInBlog) { + public Post toPost(Member member, Category category, PostId postId) { return Post.builder() - .blog(blog) + .postId(postId) .title(title) .content(content) .postThumbnailImageName(postThumbnailImageName) - .order(postIdInBlog) .writer(member) .visibilityPolish(new PostVisibilityPolicy(visibility, password)) .category(category) diff --git a/src/main/java/com/mallang/post/application/command/DeletePostCommand.java b/src/main/java/com/mallang/post/application/command/DeletePostCommand.java index 533380a5..6886b692 100644 --- a/src/main/java/com/mallang/post/application/command/DeletePostCommand.java +++ b/src/main/java/com/mallang/post/application/command/DeletePostCommand.java @@ -4,6 +4,7 @@ public record DeletePostCommand( Long memberId, - List postIds + List postIds, + String blogName ) { } diff --git a/src/main/java/com/mallang/post/application/command/StarPostCommand.java b/src/main/java/com/mallang/post/application/command/StarPostCommand.java index 8c903ed0..1308ba6a 100644 --- a/src/main/java/com/mallang/post/application/command/StarPostCommand.java +++ b/src/main/java/com/mallang/post/application/command/StarPostCommand.java @@ -4,6 +4,7 @@ public record StarPostCommand( Long postId, + String blogName, Long memberId, @Nullable String postPassword ) { diff --git a/src/main/java/com/mallang/post/application/command/UpdatePostCommand.java b/src/main/java/com/mallang/post/application/command/UpdatePostCommand.java index 012f199d..fba69fa3 100644 --- a/src/main/java/com/mallang/post/application/command/UpdatePostCommand.java +++ b/src/main/java/com/mallang/post/application/command/UpdatePostCommand.java @@ -1,6 +1,6 @@ package com.mallang.post.application.command; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.util.List; import lombok.Builder; @@ -9,6 +9,7 @@ public record UpdatePostCommand( Long memberId, Long postId, + String blogName, String title, String content, @Nullable String postThumbnailImageName, diff --git a/src/main/java/com/mallang/post/domain/Post.java b/src/main/java/com/mallang/post/domain/Post.java index 8ae35621..e0e96841 100644 --- a/src/main/java/com/mallang/post/domain/Post.java +++ b/src/main/java/com/mallang/post/domain/Post.java @@ -1,54 +1,53 @@ package com.mallang.post.domain; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; +import static jakarta.persistence.CascadeType.MERGE; import static jakarta.persistence.CascadeType.PERSIST; import static jakarta.persistence.CascadeType.REMOVE; import static jakarta.persistence.FetchType.LAZY; -import static lombok.AccessLevel.PROTECTED; import com.mallang.auth.domain.Member; import com.mallang.blog.domain.Blog; import com.mallang.category.domain.Category; -import com.mallang.common.domain.CommonDomainModel; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; import com.mallang.post.exception.DuplicatedTagsInPostException; import com.mallang.post.exception.NoAuthorityAccessPostException; import com.mallang.post.exception.PostLikeCountNegativeException; import jakarta.annotation.Nullable; import jakarta.persistence.Column; import jakarta.persistence.Embedded; +import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import jakarta.persistence.UniqueConstraint; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.domain.AbstractAggregateRoot; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter -@NoArgsConstructor(access = PROTECTED) -@Table( - name = "post", - uniqueConstraints = { - @UniqueConstraint( - columnNames = {"orders", "blog_id"} - ) - } -) +@EntityListeners(AuditingEntityListener.class) +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -public class Post extends CommonDomainModel { +public class Post extends AbstractAggregateRoot { - // TODO https://github.com/jakartaee/persistence/issues/113 해당 이슈 해결되면, 해당 방법 사용해서 자동 생성되도록 수정하기 - @Column(name = "orders", nullable = false, updatable = false) - private Long order; + @EmbeddedId + private PostId postId; + @MapsId(value = "blog_id") @ManyToOne(fetch = LAZY) - @JoinColumn(name = "blog_id", nullable = false) + @JoinColumn(name = "blog_id", nullable = false, updatable = false) private Blog blog; @Column(nullable = false) @@ -76,14 +75,17 @@ public class Post extends CommonDomainModel { private int likeCount = 0; - @OneToMany(cascade = {PERSIST, REMOVE}, orphanRemoval = true) - @JoinColumn(name = "post_id", updatable = false, nullable = false) + @OneToMany(cascade = {PERSIST, MERGE, REMOVE}, orphanRemoval = true) + @JoinColumn(name = "post_id", referencedColumnName = "post_id", updatable = false, nullable = false) + @JoinColumn(name = "blog_id", referencedColumnName = "blog_id", updatable = false, nullable = false) private List tags = new ArrayList<>(); + @CreatedDate + private LocalDateTime createdDate; + @Builder public Post( - Long order, - Blog blog, + PostId postId, String title, String content, String postThumbnailImageName, @@ -93,8 +95,7 @@ public Post( @Nullable Category category, List tags ) { - this.order = order; - this.blog = blog; + this.postId = postId; this.title = title; this.content = content; this.postThumbnailImageName = postThumbnailImageName; @@ -124,7 +125,7 @@ public void update( } public void delete() { - registerEvent(new PostDeleteEvent(getId())); + registerEvent(new PostDeleteEvent(getPostId())); } private void setTags(List tags) { @@ -158,16 +159,15 @@ public void cancelLike() { public void validatePostAccessibility(@Nullable Member member, @Nullable String postPassword) { - if (visibilityPolish.getVisibility() == Visibility.PUBLIC) { + if (visibilityPolish.getVisibility() == PUBLIC) { return; } if (getWriter().equals(member)) { return; } - if (visibilityPolish.getVisibility() == Visibility.PROTECTED) { - if (visibilityPolish.getPassword().equals(postPassword)) { - return; - } + if (visibilityPolish.getVisibility() == PROTECTED + && visibilityPolish.getPassword().equals(postPassword)) { + return; } throw new NoAuthorityAccessPostException(); } @@ -185,4 +185,25 @@ public List getTags() { .map(Tag::getContent) .toList(); } + + @Override + public List domainEvents() { + return new ArrayList<>(super.domainEvents()); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Post post)) { + return false; + } + return Objects.equals(getPostId(), post.getPostId()); + } + + @Override + public int hashCode() { + return Objects.hash(getPostId()); + } } diff --git a/src/main/java/com/mallang/post/domain/PostDeleteEvent.java b/src/main/java/com/mallang/post/domain/PostDeleteEvent.java index 11cfdf91..1322e7e4 100644 --- a/src/main/java/com/mallang/post/domain/PostDeleteEvent.java +++ b/src/main/java/com/mallang/post/domain/PostDeleteEvent.java @@ -4,16 +4,16 @@ import java.time.LocalDateTime; public record PostDeleteEvent( - Long postId, + PostId postId, LocalDateTime deletedDate ) implements DomainEvent { - public PostDeleteEvent(Long postId) { + public PostDeleteEvent(PostId postId) { this(postId, LocalDateTime.now()); } @Override - public Long id() { + public PostId id() { return postId(); } } diff --git a/src/main/java/com/mallang/post/domain/PostId.java b/src/main/java/com/mallang/post/domain/PostId.java new file mode 100644 index 00000000..6f0c186c --- /dev/null +++ b/src/main/java/com/mallang/post/domain/PostId.java @@ -0,0 +1,44 @@ +package com.mallang.post.domain; + +import static lombok.AccessLevel.PROTECTED; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import java.io.Serializable; +import java.util.Objects; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = PROTECTED) +@Getter +@Embeddable +public class PostId implements Serializable { + + @Column(name = "post_id", nullable = false, updatable = false) + private Long id; + + @Column(name = "blog_id", nullable = false, updatable = false) + private Long blogId; + + public PostId(Long id, Long blogId) { + this.id = id; + this.blogId = blogId; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof PostId postId)) { + return false; + } + return Objects.equals(getId(), postId.getId()) + && Objects.equals(getBlogId(), postId.getBlogId()); + } + + @Override + public int hashCode() { + return Objects.hash(getId(), getBlogId()); + } +} diff --git a/src/main/java/com/mallang/post/domain/PostOrderInBlogGenerator.java b/src/main/java/com/mallang/post/domain/PostOrderInBlogGenerator.java index 4bcc0319..7af65cc1 100644 --- a/src/main/java/com/mallang/post/domain/PostOrderInBlogGenerator.java +++ b/src/main/java/com/mallang/post/domain/PostOrderInBlogGenerator.java @@ -1,6 +1,5 @@ package com.mallang.post.domain; -import com.mallang.blog.domain.Blog; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -10,7 +9,8 @@ public class PostOrderInBlogGenerator { private final PostRepository postRepository; - public Long generate(Blog blog) { - return postRepository.countByBlog(blog) + 1; + public PostId generate(Long blogId) { + long postId = postRepository.countByBlog(blogId) + 1; + return new PostId(postId, blogId); } } diff --git a/src/main/java/com/mallang/post/domain/PostRepository.java b/src/main/java/com/mallang/post/domain/PostRepository.java index c5477379..048e85af 100644 --- a/src/main/java/com/mallang/post/domain/PostRepository.java +++ b/src/main/java/com/mallang/post/domain/PostRepository.java @@ -1,26 +1,39 @@ package com.mallang.post.domain; -import com.mallang.blog.domain.Blog; import com.mallang.post.exception.NotFoundPostException; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; -public interface PostRepository extends JpaRepository { +public interface PostRepository extends JpaRepository { - default Post getById(Long id) { - return findById(id).orElseThrow(NotFoundPostException::new); + default Post getByIdAndBlogName(Long postId, String blogName) { + return findByIdAndBlogName(postId, blogName).orElseThrow(NotFoundPostException::new); } - default Post getByIdAndWriterId(Long id, Long writerId) { - return findByIdAndWriterId(id, writerId).orElseThrow(NotFoundPostException::new); + @Query("SELECT p FROM Post p WHERE p.postId.id = :postId AND p.blog.name.value = :blogName") + Optional findByIdAndBlogName(@Param("postId") Long postId, + @Param("blogName") String blogName); + + default Post getByIdAndBlogNameAndWriterId(Long postId, String blogName, Long writerId) { + return findByIdAndBlogNameAndWriterId(postId, blogName, writerId) + .orElseThrow(NotFoundPostException::new); } - Optional findByIdAndWriterId(Long id, Long writerId); + @Query("SELECT p FROM Post p WHERE p.postId.id = :postId AND p.blog.name.value = :blogName AND p.writer.id = :writerId") + Optional findByIdAndBlogNameAndWriterId(@Param("postId") Long postId, + @Param("blogName") String blogName, + @Param("writerId") Long writerId); List findAllByCategoryId(Long categoryId); - List findAllByIdInAndWriterId(List ids, Long writerId); + @Query("SELECT p FROM Post p WHERE p.postId.id in :ids AND p.blog.name.value = :blogName AND p.writer.id = :writerId") + List findAllByIdInAndWriterId(@Param("ids") List ids, + @Param("blogName") String blogName, + @Param("writerId") Long writerId); - Long countByBlog(Blog blog); + @Query("SELECT COUNT(p) FROM Post p WHERE p.postId.blogId = :blogId") + Long countByBlog(Long blogId); } diff --git a/src/main/java/com/mallang/post/domain/visibility/PostVisibilityPolicy.java b/src/main/java/com/mallang/post/domain/PostVisibilityPolicy.java similarity index 97% rename from src/main/java/com/mallang/post/domain/visibility/PostVisibilityPolicy.java rename to src/main/java/com/mallang/post/domain/PostVisibilityPolicy.java index 875b40b8..f640d8cf 100644 --- a/src/main/java/com/mallang/post/domain/visibility/PostVisibilityPolicy.java +++ b/src/main/java/com/mallang/post/domain/PostVisibilityPolicy.java @@ -1,4 +1,4 @@ -package com.mallang.post.domain.visibility; +package com.mallang.post.domain; import com.mallang.post.exception.ProtectVisibilityPasswordMustRequired; import com.mallang.post.exception.VisibilityPasswordNotRequired; diff --git a/src/main/java/com/mallang/post/domain/Tag.java b/src/main/java/com/mallang/post/domain/Tag.java index dc329f4e..95735a67 100644 --- a/src/main/java/com/mallang/post/domain/Tag.java +++ b/src/main/java/com/mallang/post/domain/Tag.java @@ -1,19 +1,33 @@ package com.mallang.post.domain; +import static jakarta.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; import static org.springframework.util.ObjectUtils.isEmpty; -import com.mallang.common.domain.CommonDomainModel; import com.mallang.post.exception.BadTagContentException; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import java.time.LocalDateTime; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; @Getter @NoArgsConstructor(access = PROTECTED) @Entity -public class Tag extends CommonDomainModel { +@EntityListeners(AuditingEntityListener.class) +public class Tag { + + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + + @CreatedDate + private LocalDateTime createdDate; @Column(nullable = false, length = 30) private String content; diff --git a/src/main/java/com/mallang/post/domain/like/PostLike.java b/src/main/java/com/mallang/post/domain/like/PostLike.java index 92bb58f6..2e8332b0 100644 --- a/src/main/java/com/mallang/post/domain/like/PostLike.java +++ b/src/main/java/com/mallang/post/domain/like/PostLike.java @@ -8,6 +8,7 @@ import jakarta.annotation.Nullable; import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinColumns; import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Getter; @@ -19,7 +20,10 @@ public class PostLike extends CommonDomainModel { @ManyToOne(fetch = LAZY) - @JoinColumn(name = "post_id") + @JoinColumns({ + @JoinColumn(name = "post_id", referencedColumnName = "post_id"), + @JoinColumn(name = "blog_id", referencedColumnName = "blog_id"), + }) private Post post; @ManyToOne(fetch = LAZY) diff --git a/src/main/java/com/mallang/post/domain/like/PostLikeRepository.java b/src/main/java/com/mallang/post/domain/like/PostLikeRepository.java index 3d7f031a..5b61e0a8 100644 --- a/src/main/java/com/mallang/post/domain/like/PostLikeRepository.java +++ b/src/main/java/com/mallang/post/domain/like/PostLikeRepository.java @@ -2,6 +2,7 @@ import com.mallang.auth.domain.Member; import com.mallang.post.domain.Post; +import com.mallang.post.domain.PostId; import com.mallang.post.exception.NotFoundPostLikeException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,14 +14,22 @@ public interface PostLikeRepository extends JpaRepository { boolean existsByPostAndMember(Post post, Member member); - default PostLike getByPostIdAndMemberId(Long postId, Long memberId) { - return findByPostIdAndMemberId(postId, memberId) + default PostLike getByPostIdAndMemberId(Long postId, String blogName, Long memberId) { + return findByPostIdAndMemberId(postId, blogName, memberId) .orElseThrow(NotFoundPostLikeException::new); } - Optional findByPostIdAndMemberId(Long postId, Long memberId); + @Query(""" + SELECT pl FROM PostLike pl + WHERE pl.post.postId.id = :postId + AND pl.post.blog.name.value = :blogName + AND pl.member.id = :memberId + """) + Optional findByPostIdAndMemberId(@Param("postId") Long postId, + @Param("blogName") String blogName, + @Param("memberId") Long memberId); @Modifying - @Query("DELETE FROM PostLike pl WHERE pl.post.id = :postId") - void deleteAllByPostId(@Param("postId") Long postId); + @Query("DELETE FROM PostLike pl WHERE pl.post.postId = :postId") + void deleteAllByPostId(@Param("postId") PostId postId); } diff --git a/src/main/java/com/mallang/post/domain/star/PostStar.java b/src/main/java/com/mallang/post/domain/star/PostStar.java index db742d4a..b1f79c14 100644 --- a/src/main/java/com/mallang/post/domain/star/PostStar.java +++ b/src/main/java/com/mallang/post/domain/star/PostStar.java @@ -8,6 +8,7 @@ import jakarta.annotation.Nullable; import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinColumns; import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Getter; @@ -19,7 +20,10 @@ public class PostStar extends CommonDomainModel { @ManyToOne(fetch = LAZY) - @JoinColumn(name = "post_id") + @JoinColumns({ + @JoinColumn(name = "post_id", referencedColumnName = "post_id"), + @JoinColumn(name = "blog_id", referencedColumnName = "blog_id"), + }) private Post post; @ManyToOne(fetch = LAZY) diff --git a/src/main/java/com/mallang/post/domain/star/PostStarRepository.java b/src/main/java/com/mallang/post/domain/star/PostStarRepository.java index fc3fd464..cce8ddf7 100644 --- a/src/main/java/com/mallang/post/domain/star/PostStarRepository.java +++ b/src/main/java/com/mallang/post/domain/star/PostStarRepository.java @@ -2,6 +2,7 @@ import com.mallang.auth.domain.Member; import com.mallang.post.domain.Post; +import com.mallang.post.domain.PostId; import com.mallang.post.exception.NotFoundPostStarException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,14 +14,22 @@ public interface PostStarRepository extends JpaRepository { boolean existsByPostAndMember(Post post, Member member); - default PostStar getByPostIdAndMemberId(Long postId, Long memberId) { - return findByPostIdAndMemberId(postId, memberId) + default PostStar getByPostIdAndBlogNameAndMemberId(Long postId, String blogName, Long memberId) { + return findByPostIdAndBlogNameAndMemberId(postId, blogName, memberId) .orElseThrow(NotFoundPostStarException::new); } - Optional findByPostIdAndMemberId(Long postId, Long memberId); + @Query(""" + SELECT ps FROM PostStar ps + WHERE ps.post.postId.id = :postId + AND ps.post.blog.name.value = :blogName + AND ps.member.id = :memberId + """) + Optional findByPostIdAndBlogNameAndMemberId(@Param("postId") Long postId, + @Param("blogName") String blogName, + @Param("memberId") Long memberId); @Modifying - @Query("DELETE FROM PostStar ps WHERE ps.post.id = :postId") - void deleteAllByPostId(@Param("postId") Long postId); + @Query("DELETE FROM PostStar ps WHERE ps.post.postId = :postId") + void deleteAllByPostId(@Param("postId") PostId postId); } diff --git a/src/main/java/com/mallang/post/presentation/PostController.java b/src/main/java/com/mallang/post/presentation/PostController.java index 23283a44..4ffbd2e2 100644 --- a/src/main/java/com/mallang/post/presentation/PostController.java +++ b/src/main/java/com/mallang/post/presentation/PostController.java @@ -26,13 +26,14 @@ public class PostController { private final PostQueryService postQueryService; - @GetMapping("/{id}") + @GetMapping("/{blogName}/{id}") public ResponseEntity getById( @OptionalAuth Long memberId, @CookieValue(name = POST_PASSWORD_COOKIE, required = false) String postPassword, + @PathVariable(name = "blogName") String blogName, @PathVariable(name = "id") Long id ) { - return ResponseEntity.ok(postQueryService.getById(memberId, postPassword, id)); + return ResponseEntity.ok(postQueryService.getByIdAndBlogName(id, blogName, memberId, postPassword)); } @GetMapping @@ -41,6 +42,6 @@ public ResponseEntity> search( @ModelAttribute PostSearchCond postSearchCond, @PageableDefault(size = 9) Pageable pageable ) { - return ResponseEntity.ok(PageResponse.from(postQueryService.search(memberId, postSearchCond, pageable))); + return ResponseEntity.ok(PageResponse.from(postQueryService.search(postSearchCond, pageable, memberId))); } } diff --git a/src/main/java/com/mallang/post/presentation/PostManageController.java b/src/main/java/com/mallang/post/presentation/PostManageController.java index 2cae00e8..456877b2 100644 --- a/src/main/java/com/mallang/post/presentation/PostManageController.java +++ b/src/main/java/com/mallang/post/presentation/PostManageController.java @@ -3,6 +3,7 @@ import com.mallang.auth.presentation.support.Auth; import com.mallang.common.presentation.PageResponse; import com.mallang.post.application.PostService; +import com.mallang.post.domain.PostId; import com.mallang.post.presentation.request.CreatePostRequest; import com.mallang.post.presentation.request.DeletePostRequest; import com.mallang.post.presentation.request.UpdatePostRequest; @@ -38,8 +39,9 @@ public ResponseEntity create( @Auth Long memberId, @RequestBody CreatePostRequest request ) { - Long id = postService.create(request.toCommand(memberId)); - return ResponseEntity.created(URI.create("/posts/" + id)).build(); + PostId id = postService.create(request.toCommand(memberId)); + URI uri = URI.create("/posts/%s/%d".formatted(request.blogName(), id.getId())); + return ResponseEntity.created(uri).build(); } @PutMapping("/{id}") @@ -61,12 +63,13 @@ public ResponseEntity delete( return ResponseEntity.noContent().build(); } - @GetMapping("/{id}") + @GetMapping("/{blogName}/{id}") public ResponseEntity getById( + @PathVariable(name = "blogName") String blogName, @PathVariable(name = "id") Long postId, @Auth Long memberId ) { - return ResponseEntity.ok(postManageQueryService.findById(memberId, postId)); + return ResponseEntity.ok(postManageQueryService.findById(memberId, postId, blogName)); } @GetMapping diff --git a/src/main/java/com/mallang/post/presentation/request/CancelPostLikeRequest.java b/src/main/java/com/mallang/post/presentation/request/CancelPostLikeRequest.java index 419937aa..8e883cd1 100644 --- a/src/main/java/com/mallang/post/presentation/request/CancelPostLikeRequest.java +++ b/src/main/java/com/mallang/post/presentation/request/CancelPostLikeRequest.java @@ -4,10 +4,11 @@ import jakarta.annotation.Nullable; public record CancelPostLikeRequest( - Long postId + Long postId, + String blogName ) { public CancelPostLikeCommand toCommand(Long memberId, @Nullable String postPassword) { - return new CancelPostLikeCommand(postId, memberId, postPassword); + return new CancelPostLikeCommand(postId, blogName, memberId, postPassword); } } diff --git a/src/main/java/com/mallang/post/presentation/request/CancelPostStarRequest.java b/src/main/java/com/mallang/post/presentation/request/CancelPostStarRequest.java index 41b1cc58..dfc3c1cf 100644 --- a/src/main/java/com/mallang/post/presentation/request/CancelPostStarRequest.java +++ b/src/main/java/com/mallang/post/presentation/request/CancelPostStarRequest.java @@ -3,10 +3,11 @@ import com.mallang.post.application.command.CancelPostStarCommand; public record CancelPostStarRequest( - Long postId + Long postId, + String blogName ) { public CancelPostStarCommand toCommand(Long memberId) { - return new CancelPostStarCommand(postId, memberId); + return new CancelPostStarCommand(memberId, postId, blogName); } } diff --git a/src/main/java/com/mallang/post/presentation/request/ClickPostLikeRequest.java b/src/main/java/com/mallang/post/presentation/request/ClickPostLikeRequest.java index 73eaa92d..736a207d 100644 --- a/src/main/java/com/mallang/post/presentation/request/ClickPostLikeRequest.java +++ b/src/main/java/com/mallang/post/presentation/request/ClickPostLikeRequest.java @@ -4,10 +4,11 @@ import jakarta.annotation.Nullable; public record ClickPostLikeRequest( - Long postId + Long postId, + String blogName ) { public ClickPostLikeCommand toCommand(Long memberId, @Nullable String postPassword) { - return new ClickPostLikeCommand(postId, memberId, postPassword); + return new ClickPostLikeCommand(postId, blogName, memberId, postPassword); } } diff --git a/src/main/java/com/mallang/post/presentation/request/CreatePostRequest.java b/src/main/java/com/mallang/post/presentation/request/CreatePostRequest.java index 4d21e984..0db4ba4b 100644 --- a/src/main/java/com/mallang/post/presentation/request/CreatePostRequest.java +++ b/src/main/java/com/mallang/post/presentation/request/CreatePostRequest.java @@ -1,7 +1,7 @@ package com.mallang.post.presentation.request; import com.mallang.post.application.command.CreatePostCommand; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.util.List; diff --git a/src/main/java/com/mallang/post/presentation/request/DeletePostRequest.java b/src/main/java/com/mallang/post/presentation/request/DeletePostRequest.java index dff2e58b..13cb305f 100644 --- a/src/main/java/com/mallang/post/presentation/request/DeletePostRequest.java +++ b/src/main/java/com/mallang/post/presentation/request/DeletePostRequest.java @@ -4,9 +4,10 @@ import java.util.List; public record DeletePostRequest( - List postIds + List postIds, + String blogName ) { public DeletePostCommand toCommand(Long memberId) { - return new DeletePostCommand(memberId, postIds); + return new DeletePostCommand(memberId, postIds, blogName); } } diff --git a/src/main/java/com/mallang/post/presentation/request/StarPostRequest.java b/src/main/java/com/mallang/post/presentation/request/StarPostRequest.java index 607852c0..336cd001 100644 --- a/src/main/java/com/mallang/post/presentation/request/StarPostRequest.java +++ b/src/main/java/com/mallang/post/presentation/request/StarPostRequest.java @@ -4,10 +4,11 @@ import jakarta.annotation.Nullable; public record StarPostRequest( - Long postId + Long postId, + String blogName ) { public StarPostCommand toCommand(Long memberId, @Nullable String postPassword) { - return new StarPostCommand(postId, memberId, postPassword); + return new StarPostCommand(postId, blogName, memberId, postPassword); } } diff --git a/src/main/java/com/mallang/post/presentation/request/UpdatePostRequest.java b/src/main/java/com/mallang/post/presentation/request/UpdatePostRequest.java index 5b91dd70..f36f5929 100644 --- a/src/main/java/com/mallang/post/presentation/request/UpdatePostRequest.java +++ b/src/main/java/com/mallang/post/presentation/request/UpdatePostRequest.java @@ -1,11 +1,12 @@ package com.mallang.post.presentation.request; import com.mallang.post.application.command.UpdatePostCommand; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.util.List; public record UpdatePostRequest( + String blogName, String title, String content, @Nullable String postThumbnailImageName, @@ -20,6 +21,7 @@ public UpdatePostCommand toCommand(Long memberId, Long postId) { return UpdatePostCommand.builder() .memberId(memberId) .postId(postId) + .blogName(blogName) .title(title) .content(content) .postThumbnailImageName(postThumbnailImageName) diff --git a/src/main/java/com/mallang/post/query/PostDataProtector.java b/src/main/java/com/mallang/post/query/PostDataProtector.java index 3bb759d1..b47c1d22 100644 --- a/src/main/java/com/mallang/post/query/PostDataProtector.java +++ b/src/main/java/com/mallang/post/query/PostDataProtector.java @@ -1,6 +1,6 @@ package com.mallang.post.query; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.query.response.PostDetailResponse; import com.mallang.post.query.response.PostSearchResponse; import com.mallang.post.query.response.StaredPostResponse; @@ -28,6 +28,7 @@ public PostDetailResponse protectIfRequired( } return new PostDetailResponse( postDetailResponse.id(), + postDetailResponse.blogName(), postDetailResponse.title(), "보호되어 있는 글입니다. 내용을 보시려면 비밀번호를 입력하세요.", "", @@ -57,6 +58,7 @@ private PostSearchResponse protectIfRequired(Long memberId, PostSearchResponse p } return new PostSearchResponse( postSearchResponse.id(), + postSearchResponse.blogName(), postSearchResponse.title(), "보호되어 있는 글입니다.", "", @@ -91,6 +93,7 @@ private StaredPostResponse protectStaredIfRequired( data.starId(), data.staredData(), data.postId(), + data.blogName(), data.title(), "보호되어 있는 글입니다.", "", diff --git a/src/main/java/com/mallang/post/query/PostDataValidator.java b/src/main/java/com/mallang/post/query/PostDataValidator.java index 38ff2e7d..9e4d26d7 100644 --- a/src/main/java/com/mallang/post/query/PostDataValidator.java +++ b/src/main/java/com/mallang/post/query/PostDataValidator.java @@ -1,6 +1,6 @@ package com.mallang.post.query; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.exception.NoAuthorityAccessPostException; import com.mallang.post.query.response.PostDetailResponse; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/mallang/post/query/PostManageQueryService.java b/src/main/java/com/mallang/post/query/PostManageQueryService.java index 6e09c32d..f2465df0 100644 --- a/src/main/java/com/mallang/post/query/PostManageQueryService.java +++ b/src/main/java/com/mallang/post/query/PostManageQueryService.java @@ -19,8 +19,8 @@ public class PostManageQueryService { private final PostManageDetailDao postManageDetailDao; private final PostManageSearchDao postManageSearchDao; - public PostManageDetailResponse findById(Long memberId, Long id) { - return postManageDetailDao.find(memberId, id); + public PostManageDetailResponse findById(Long memberId, Long id, String blogName) { + return postManageDetailDao.find(memberId, id, blogName); } public Page search(Long memberId, PostManageSearchCond cond, Pageable pageable) { diff --git a/src/main/java/com/mallang/post/query/PostQueryService.java b/src/main/java/com/mallang/post/query/PostQueryService.java index 4617e331..54ce063d 100644 --- a/src/main/java/com/mallang/post/query/PostQueryService.java +++ b/src/main/java/com/mallang/post/query/PostQueryService.java @@ -22,13 +22,16 @@ public class PostQueryService { private final PostDataValidator postDataValidator; private final PostDataProtector postDataProtector; - public PostDetailResponse getById(@Nullable Long memberId, @Nullable String postPassword, Long id) { - PostDetailResponse postDetailResponse = postDetailDao.find(memberId, id); + public PostDetailResponse getByIdAndBlogName(Long id, + String blogName, + @Nullable Long memberId, + @Nullable String postPassword) { + PostDetailResponse postDetailResponse = postDetailDao.find(id, blogName, memberId); postDataValidator.validateAccessPost(memberId, postDetailResponse); return postDataProtector.protectIfRequired(memberId, postPassword, postDetailResponse); } - public Page search(@Nullable Long memberId, PostSearchCond cond, Pageable pageable) { + public Page search(PostSearchCond cond, Pageable pageable, @Nullable Long memberId) { Page result = postSearchDao.search(memberId, cond, pageable); return postDataProtector.protectIfRequired(memberId, result); } diff --git a/src/main/java/com/mallang/post/query/dao/PostDetailDao.java b/src/main/java/com/mallang/post/query/dao/PostDetailDao.java index 385c5343..a9185477 100644 --- a/src/main/java/com/mallang/post/query/dao/PostDetailDao.java +++ b/src/main/java/com/mallang/post/query/dao/PostDetailDao.java @@ -16,11 +16,11 @@ public class PostDetailDao { private final PostQuerySupport postQuerySupport; private final PostLikeQuerySupport postLikeQuerySupport; - public PostDetailResponse find(@Nullable Long memberId, Long id) { + public PostDetailResponse find(Long id, String blogName, @Nullable Long memberId) { if (memberId == null) { - return PostDetailResponse.from(postQuerySupport.getById(id)); + return PostDetailResponse.from(postQuerySupport.getByIdAndBlogName(id, blogName)); } - boolean isLiked = postLikeQuerySupport.existsByMemberIdAndPostId(memberId, id); - return PostDetailResponse.withLiked(postQuerySupport.getById(id), isLiked); + boolean isLiked = postLikeQuerySupport.existsByMemberIdAndPostId(memberId, id, blogName); + return PostDetailResponse.withLiked(postQuerySupport.getByIdAndBlogName(id, blogName), isLiked); } } diff --git a/src/main/java/com/mallang/post/query/dao/PostManageDetailDao.java b/src/main/java/com/mallang/post/query/dao/PostManageDetailDao.java index 3a179c9f..a03d676e 100644 --- a/src/main/java/com/mallang/post/query/dao/PostManageDetailDao.java +++ b/src/main/java/com/mallang/post/query/dao/PostManageDetailDao.java @@ -13,7 +13,8 @@ public class PostManageDetailDao { private final PostQuerySupport postQuerySupport; - public PostManageDetailResponse find(Long memberId, Long id) { - return PostManageDetailResponse.from(postQuerySupport.getByIdAndWriterId(id, memberId)); + public PostManageDetailResponse find(Long memberId, Long id, String blogName) { + return PostManageDetailResponse.from(postQuerySupport + .getByPostIdAndBlogNameAndWriterId(id, blogName, memberId)); } } diff --git a/src/main/java/com/mallang/post/query/dao/PostManageSearchDao.java b/src/main/java/com/mallang/post/query/dao/PostManageSearchDao.java index a13f7a0e..2c016579 100644 --- a/src/main/java/com/mallang/post/query/dao/PostManageSearchDao.java +++ b/src/main/java/com/mallang/post/query/dao/PostManageSearchDao.java @@ -6,7 +6,7 @@ import com.mallang.category.query.support.CategoryQuerySupport; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.query.response.PostManageSearchResponse; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQuery; @@ -51,7 +51,7 @@ public Page search(Long memberId, PostManageSearchCond contentContains(cond.content()), visibilityEq(cond.visibility()) ) - .orderBy(post.id.desc()) + .orderBy(post.postId.id.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); diff --git a/src/main/java/com/mallang/post/query/dao/PostSearchDao.java b/src/main/java/com/mallang/post/query/dao/PostSearchDao.java index 9bdd2ec3..db46612c 100644 --- a/src/main/java/com/mallang/post/query/dao/PostSearchDao.java +++ b/src/main/java/com/mallang/post/query/dao/PostSearchDao.java @@ -1,10 +1,11 @@ package com.mallang.post.query.dao; import static com.mallang.auth.domain.QMember.member; +import static com.mallang.blog.domain.QBlog.blog; import static com.mallang.category.domain.QCategory.category; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; import static com.mallang.post.domain.QPost.post; import static com.mallang.post.domain.QTag.tag; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; import static org.springframework.data.support.PageableExecutionUtils.getPage; import com.mallang.category.query.support.CategoryQuerySupport; @@ -45,6 +46,7 @@ public Page search(@Nullable Long memberId, PostSearchCond c ); List result = query.selectFrom(post) .distinct() + .leftJoin(post.blog, blog).fetchJoin() .leftJoin(post.tags, tag) .join(post.writer, member).fetchJoin() .leftJoin(post.category, category).fetchJoin() @@ -56,7 +58,7 @@ public Page search(@Nullable Long memberId, PostSearchCond c writerIdEq(cond.writerId()), titleOrContentContains(cond.title(), cond.content(), cond.titleOrContent()) ) - .orderBy(post.id.desc()) + .orderBy(post.createdDate.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); diff --git a/src/main/java/com/mallang/post/query/dao/StaredPostDao.java b/src/main/java/com/mallang/post/query/dao/StaredPostDao.java index 3d2b0701..dbc7d49b 100644 --- a/src/main/java/com/mallang/post/query/dao/StaredPostDao.java +++ b/src/main/java/com/mallang/post/query/dao/StaredPostDao.java @@ -1,9 +1,9 @@ package com.mallang.post.query.dao; import static com.mallang.auth.domain.QMember.member; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; import static com.mallang.post.domain.QPost.post; import static com.mallang.post.domain.star.QPostStar.postStar; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; import com.mallang.post.domain.star.PostStar; import com.mallang.post.query.response.StaredPostResponse; diff --git a/src/main/java/com/mallang/post/query/response/PostDetailResponse.java b/src/main/java/com/mallang/post/query/response/PostDetailResponse.java index 5f068068..4ab0fd86 100644 --- a/src/main/java/com/mallang/post/query/response/PostDetailResponse.java +++ b/src/main/java/com/mallang/post/query/response/PostDetailResponse.java @@ -4,7 +4,7 @@ import com.mallang.auth.domain.Member; import com.mallang.category.domain.Category; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.time.LocalDateTime; import java.util.List; @@ -13,6 +13,7 @@ @Builder public record PostDetailResponse( Long id, + String blogName, String title, String content, @Nullable String postThumbnailImageName, @@ -32,7 +33,8 @@ public static PostDetailResponse from(Post post) { public static PostDetailResponse withLiked(Post post, boolean isLiked) { return PostDetailResponse.builder() - .id(post.getId()) + .id(post.getPostId().getId()) + .blogName(post.getBlog().getName()) .title(post.getTitle()) .content(post.getContent()) .postThumbnailImageName(post.getPostThumbnailImageName()) diff --git a/src/main/java/com/mallang/post/query/response/PostManageDetailResponse.java b/src/main/java/com/mallang/post/query/response/PostManageDetailResponse.java index 5a46c085..5cbe01d2 100644 --- a/src/main/java/com/mallang/post/query/response/PostManageDetailResponse.java +++ b/src/main/java/com/mallang/post/query/response/PostManageDetailResponse.java @@ -2,7 +2,7 @@ import com.mallang.category.domain.Category; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.time.LocalDateTime; import java.util.List; @@ -23,7 +23,7 @@ public record PostManageDetailResponse( ) { public static PostManageDetailResponse from(Post post) { return PostManageDetailResponse.builder() - .id(post.getId()) + .id(post.getPostId().getId()) .title(post.getTitle()) .intro(post.getPostIntro()) .content(post.getContent()) diff --git a/src/main/java/com/mallang/post/query/response/PostManageSearchResponse.java b/src/main/java/com/mallang/post/query/response/PostManageSearchResponse.java index eb786be5..c892cf86 100644 --- a/src/main/java/com/mallang/post/query/response/PostManageSearchResponse.java +++ b/src/main/java/com/mallang/post/query/response/PostManageSearchResponse.java @@ -2,7 +2,7 @@ import com.mallang.category.domain.Category; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import java.time.LocalDateTime; import lombok.Builder; @@ -17,7 +17,7 @@ public record PostManageSearchResponse( ) { public static PostManageSearchResponse from(Post post) { return PostManageSearchResponse.builder() - .id(post.getId()) + .id(post.getPostId().getId()) .title(post.getTitle()) .visibility(post.getVisibilityPolish().getVisibility()) .password(post.getVisibilityPolish().getPassword()) diff --git a/src/main/java/com/mallang/post/query/response/PostSearchResponse.java b/src/main/java/com/mallang/post/query/response/PostSearchResponse.java index 25b05c79..98d7a87d 100644 --- a/src/main/java/com/mallang/post/query/response/PostSearchResponse.java +++ b/src/main/java/com/mallang/post/query/response/PostSearchResponse.java @@ -3,7 +3,7 @@ import com.mallang.auth.domain.Member; import com.mallang.category.domain.Category; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.time.LocalDateTime; import java.util.List; @@ -12,6 +12,7 @@ @Builder public record PostSearchResponse( Long id, + String blogName, String title, String content, String intro, @@ -25,7 +26,8 @@ public record PostSearchResponse( ) { public static PostSearchResponse from(Post post) { return PostSearchResponse.builder() - .id(post.getId()) + .id(post.getPostId().getId()) + .blogName(post.getBlog().getName()) .title(post.getTitle()) .content(post.getContent()) .intro(post.getPostIntro()) diff --git a/src/main/java/com/mallang/post/query/response/StaredPostResponse.java b/src/main/java/com/mallang/post/query/response/StaredPostResponse.java index 2ac0522d..a6e9ade2 100644 --- a/src/main/java/com/mallang/post/query/response/StaredPostResponse.java +++ b/src/main/java/com/mallang/post/query/response/StaredPostResponse.java @@ -3,8 +3,8 @@ import com.mallang.auth.domain.Member; import com.mallang.category.domain.Category; import com.mallang.post.domain.Post; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.domain.star.PostStar; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; import jakarta.annotation.Nullable; import java.time.LocalDateTime; import java.util.List; @@ -15,6 +15,7 @@ public record StaredPostResponse( Long starId, LocalDateTime staredData, Long postId, + String blogName, String title, String content, String intro, @@ -30,7 +31,8 @@ public static StaredPostResponse from(PostStar postStar) { return StaredPostResponse.builder() .starId(postStar.getId()) .staredData(postStar.getCreatedDate()) - .postId(post.getId()) + .postId(post.getPostId().getId()) + .blogName(post.getBlog().getName()) .title(post.getTitle()) .content(post.getContent()) .intro(post.getPostIntro()) diff --git a/src/main/java/com/mallang/post/query/support/PostLikeQuerySupport.java b/src/main/java/com/mallang/post/query/support/PostLikeQuerySupport.java index 4426252a..a3751b1b 100644 --- a/src/main/java/com/mallang/post/query/support/PostLikeQuerySupport.java +++ b/src/main/java/com/mallang/post/query/support/PostLikeQuerySupport.java @@ -10,15 +10,21 @@ public interface PostLikeQuerySupport extends JpaRepository { default boolean existsByMemberIdAndPostId( Long memberId, - Long postId + Long postId, + String blogName ) { - // TODO 이거 VS findTop1ByMemberIdAndBlogNameAndPostId 이거랑 성능차이 있나 확인하기 - return findByMemberIdAndPostId(memberId, postId).isPresent(); + return findByMemberIdAndPostId(memberId, postId, blogName).isPresent(); } - @Query("SELECT pl FROM PostLike pl WHERE pl.member.id = :memberId AND pl.post.id = :postId") + @Query(""" + SELECT pl FROM PostLike pl + WHERE pl.member.id = :memberId + AND pl.post.postId.id = :postId + AND pl.post.blog.name.value = :blogName + """) Optional findByMemberIdAndPostId( @Param("memberId") Long memberId, - @Param("postId") Long postId + @Param("postId") Long postId, + @Param("blogName") String blogName ); } diff --git a/src/main/java/com/mallang/post/query/support/PostQuerySupport.java b/src/main/java/com/mallang/post/query/support/PostQuerySupport.java index 8080bc56..36690e3a 100644 --- a/src/main/java/com/mallang/post/query/support/PostQuerySupport.java +++ b/src/main/java/com/mallang/post/query/support/PostQuerySupport.java @@ -4,16 +4,33 @@ import com.mallang.post.exception.NotFoundPostException; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface PostQuerySupport extends JpaRepository { - default Post getById(Long id) { - return findById(id).orElseThrow(NotFoundPostException::new); + default Post getByIdAndBlogName(Long id, String blogName) { + return findByIdAndBlogName(id, blogName) + .orElseThrow(NotFoundPostException::new); } - default Post getByIdAndWriterId(Long id, Long writerId) { - return findByIdAndWriterId(id, writerId).orElseThrow(NotFoundPostException::new); + @Query("SELECT p FROM Post p WHERE p.postId.id = :id AND p.blog.name.value = :blogName") + Optional findByIdAndBlogName(@Param("id") Long id, + @Param("blogName") String blogName); + + default Post getByPostIdAndBlogNameAndWriterId(Long id, String blogName, Long writerId) { + return findByPostIdAndBlogNameAndWriterId(id, blogName, writerId).orElseThrow(NotFoundPostException::new); } - Optional findByIdAndWriterId(Long id, Long writerId); + @Query(""" + SELECT p FROM Post p + WHERE p.postId.id = :id + AND p.blog.name.value = :blogName + AND p.writer.id = :writerId + """) + Optional findByPostIdAndBlogNameAndWriterId( + @Param("id") Long id, + @Param("blogName") String blogName, + @Param("writerId") Long writerId + ); } diff --git a/src/main/java/com/mallang/statistics/statistic/collector/PostViewHistoryAop.java b/src/main/java/com/mallang/statistics/statistic/collector/PostViewHistoryAop.java index 63157a4d..ad85d038 100644 --- a/src/main/java/com/mallang/statistics/statistic/collector/PostViewHistoryAop.java +++ b/src/main/java/com/mallang/statistics/statistic/collector/PostViewHistoryAop.java @@ -27,12 +27,12 @@ public class PostViewHistoryAop { private final PostViewHistoryCollector postViewHistoryCollector; - @Pointcut("execution(* com.mallang.post.query.PostQueryService.getById(..))") - public void postQueryServiceGetById() { + @Pointcut("execution(* com.mallang.post.query.PostQueryService.getByIdAndBlogName(..))") + public void postQueryServiceGetByIdAndBlogName() { } @AfterReturning( - pointcut = "postQueryServiceGetById()", + pointcut = "postQueryServiceGetByIdAndBlogName()", returning = "result" ) public void history(PostDetailResponse result) { diff --git a/src/test/java/com/mallang/acceptance/category/CategoryAcceptanceTest.java b/src/test/java/com/mallang/acceptance/category/CategoryAcceptanceTest.java index 85b34f46..ce41d82d 100644 --- a/src/test/java/com/mallang/acceptance/category/CategoryAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/category/CategoryAcceptanceTest.java @@ -18,7 +18,7 @@ import static com.mallang.acceptance.category.CategoryAcceptanceSteps.카테고리_조회_응답을_검증한다; import static com.mallang.acceptance.post.PostAcceptanceSteps.포스트_단일_조회_요청; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_생성; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; @@ -152,7 +152,8 @@ void setUp() { // then 응답_상태를_검증한다(응답, 정상_처리); - var 포스트_조회_응답 = 포스트_단일_조회_요청(null, 포스트_ID, null).as(PostDetailResponse.class); + var 포스트_조회_응답 = 포스트_단일_조회_요청(null, 포스트_ID, 말랑_블로그_이름, null) + .as(PostDetailResponse.class); assertThat(포스트_조회_응답.category().categoryId()).isNull(); } diff --git a/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceSteps.java index 71bdca10..a3db57ae 100644 --- a/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceSteps.java @@ -139,19 +139,22 @@ public class CommentAcceptanceSteps { public static ExtractableResponse 특정_포스트의_댓글_전체_조회_요청( Long 포스트_ID, + String 블로그_이름, @Nullable String 포스트_비밀번호 ) { - return 특정_포스트의_댓글_전체_조회_요청(null, 포스트_ID, 포스트_비밀번호); + return 특정_포스트의_댓글_전체_조회_요청(null, 포스트_ID, 블로그_이름, 포스트_비밀번호); } public static ExtractableResponse 특정_포스트의_댓글_전체_조회_요청( String 세션_ID, Long 포스트_ID, + String 블로그_이름, @Nullable String 포스트_비밀번호 ) { return given(세션_ID) .cookie(POST_PASSWORD_COOKIE, 포스트_비밀번호) .queryParam("postId", 포스트_ID) + .queryParam("blogName", 블로그_이름) .get("/comments") .then().log().all() .extract(); diff --git a/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceTest.java b/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceTest.java index 54565905..8e110eec 100644 --- a/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/comment/CommentAcceptanceTest.java @@ -27,7 +27,7 @@ import static com.mallang.acceptance.post.PostManageAcceptanceSteps.비공개_포스트_생성_데이터; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_생성; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_수정_요청; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; import static java.util.Collections.emptyList; import com.mallang.acceptance.AcceptanceTest; @@ -74,9 +74,10 @@ protected void setUp() { 공개_포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); 보호_포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(말랑_블로그_이름)); 비공개_포스트_ID = 포스트_생성(말랑_세션_ID, 비공개_포스트_생성_데이터(말랑_블로그_이름)); - 비인증_댓글_작성_요청 = new WriteUnAuthCommentRequest(공개_포스트_ID, "댓글", "비인증", "1234", null); - 인증_댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, "댓글", 공개, null); + 비인증_댓글_작성_요청 = new WriteUnAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "댓글", "비인증", "1234", null); + 인증_댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "댓글", 공개, null); 공개_포스트를_비공개로_바꾸는_요청 = new UpdatePostRequest( + 말랑_블로그_이름, "보호로 변경", "보호", null, @@ -112,7 +113,7 @@ class 댓글_작성_API { @Test void 로그인한_사용자는_비밀_댓글을_작성할_수_있다() { // when - var 비공개_댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, "댓글", 비공개, null); + var 비공개_댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 응답 = 댓글_작성_요청(동훈_세션_ID, 비공개_댓글_작성_요청, null); // then @@ -123,7 +124,7 @@ class 댓글_작성_API { void 대댓글을_작성할_수_있다() { // given var 댓글_ID = 댓글_작성(동훈_세션_ID, 인증_댓글_작성_요청, null); - var 대댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, "대댓글", 비공개, 댓글_ID); + var 대댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "대댓글", 비공개, 댓글_ID); // when var 응답 = 댓글_작성_요청(동훈_세션_ID, 대댓글_작성_요청, null); @@ -136,9 +137,9 @@ class 댓글_작성_API { void 대댓글에_대해_댓글을_달_수_없다() { // given var 댓글_ID = 댓글_작성(동훈_세션_ID, 인증_댓글_작성_요청, null); - var 대댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, "대댓글", 비공개, 댓글_ID); + var 대댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "대댓글", 비공개, 댓글_ID); var 대댓글_ID = 댓글_작성(동훈_세션_ID, 대댓글_작성_요청, null); - var 대대댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, "대대댓글", 비공개, 대댓글_ID); + var 대대댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "대대댓글", 비공개, 대댓글_ID); // when var 응답 = 댓글_작성_요청(동훈_세션_ID, 대대댓글_작성_요청, null); @@ -154,7 +155,7 @@ class 보호된_포스트인_경우 { @BeforeEach void setUp() { - 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, "댓글", 비공개, null); + 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); } @Nested @@ -188,7 +189,7 @@ class 블로그_주인이_아닌_경우 { void 대댓글로_남기는_것_역시_불가하다() { // given var 댓글_ID = 댓글_작성(동훈_세션_ID, 댓글_작성_요청, "1234"); - var 대댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, "댓글", 비공개, 댓글_ID); + var 대댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, 댓글_ID); // when var 응답 = 댓글_작성_요청(동훈_세션_ID, 대댓글_작성_요청, null); @@ -200,7 +201,7 @@ class 블로그_주인이_아닌_경우 { @Test void 회원가입_여부에_관계없이_입력한_비밀번호가_포스트의_비밀번호와_일치하면_작성할_수_있다() { // when - var 댓글_작성_요청 = new WriteUnAuthCommentRequest(보호_포스트_ID, "댓글", "익명입니다", "댓글비번", null); + var 댓글_작성_요청 = new WriteUnAuthCommentRequest(보호_포스트_ID, 말랑_블로그_이름, "댓글", "익명입니다", "댓글비번", null); var 응답 = 비인증_댓글_작성_요청(댓글_작성_요청, "1234"); // then @@ -216,7 +217,7 @@ class 비공개_포스트인_경우 { @BeforeEach void setUp() { - 댓글_작성_요청 = new WriteAuthCommentRequest(비공개_포스트_ID, "댓글", 비공개, null); + 댓글_작성_요청 = new WriteAuthCommentRequest(비공개_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); } @Test @@ -247,9 +248,10 @@ class 댓글_수정_API { @BeforeEach void setUp() { - 동훈_댓글_ID = 댓글_작성(동훈_세션_ID, new WriteAuthCommentRequest(공개_포스트_ID, "좋은 글 감사합니다", 비공개, null), null); + 동훈_댓글_ID = 댓글_작성(동훈_세션_ID, new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "좋은 글 감사합니다", 비공개, null), + null); 비인증_댓글_ID = 비인증_댓글_작성( - new WriteUnAuthCommentRequest(공개_포스트_ID, "좋은 글 감사합니다", "비인증입니다", "1234", null), null); + new WriteUnAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "좋은 글 감사합니다", "비인증입니다", "1234", null), null); } @Test @@ -305,7 +307,7 @@ class 보호된_포스트인_경우 { @BeforeEach void setUp() { - 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, "댓글", 비공개, null); + 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); 댓글_수정_요청 = new UpdateAuthCommentRequest("수정", 비공개); } @@ -362,7 +364,7 @@ class 비공개_포스트인_경우 { @Test void 블로그_주인은_수정_가능하다() { // given - var 댓글_작성_요청 = new WriteAuthCommentRequest(비공개_포스트_ID, "댓글", 비공개, null); + var 댓글_작성_요청 = new WriteAuthCommentRequest(비공개_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 댓글_ID = 댓글_작성(말랑_세션_ID, 댓글_작성_요청, null); // when @@ -374,7 +376,7 @@ class 비공개_포스트인_경우 { @Test void 블로그_주인이_아닌_경우_수정할_수_없다() { - var 댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, "댓글", 비공개, null); + var 댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 댓글_ID = 댓글_작성(동훈_세션_ID, 댓글_작성_요청, null); 포스트_수정_요청(말랑_세션_ID, 공개_포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); @@ -395,8 +397,9 @@ class 댓글_삭제_API { @BeforeEach void setUp() { - var authRequest = new WriteAuthCommentRequest(공개_포스트_ID, "좋은 글 감사합니다", 비공개, null); - var unAuthRequest = new WriteUnAuthCommentRequest(공개_포스트_ID, "좋은 글 감사합니다", "비인증입니다", "1234", null); + var authRequest = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "좋은 글 감사합니다", 비공개, null); + var unAuthRequest = new WriteUnAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "좋은 글 감사합니다", "비인증입니다", "1234", + null); 동훈_댓글_ID = 댓글_작성(동훈_세션_ID, authRequest, null); 비인증_댓글_ID = 비인증_댓글_작성(unAuthRequest, null); } @@ -449,7 +452,8 @@ void setUp() { @Test void 대댓글도_삭제가_가능하다() { // given - var 대댓글_ID = 댓글_작성(말랑_세션_ID, new WriteAuthCommentRequest(공개_포스트_ID, "대댓글입니다", 공개, 동훈_댓글_ID), null); + var 대댓글_ID = 댓글_작성(말랑_세션_ID, new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "대댓글입니다", 공개, 동훈_댓글_ID), + null); // when var 응답 = 댓글_삭제_요청(말랑_세션_ID, 대댓글_ID, null); @@ -463,10 +467,10 @@ void setUp() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "좋은 글 감사합니다", "비인증", "1234", null); + var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "좋은 글 감사합니다", "비인증", "1234", null); var 댓글_ID = 비인증_댓글_작성(댓글_작성_요청, null); - var 대댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "대댓글입니다", 공개, 댓글_ID); + var 대댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "대댓글입니다", 공개, 댓글_ID); var 대댓글_ID = 댓글_작성(말랑_세션_ID, 대댓글_작성_요청, null); // when @@ -474,7 +478,7 @@ void setUp() { // then 응답_상태를_검증한다(응답, 정상_처리); - var 댓글_조회_응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, null); + var 댓글_조회_응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, 말랑_블로그_이름, null); 특정_포스트의_댓글_전체_조회_응답을_검증한다(댓글_조회_응답, List.of( new UnAuthCommentResponse( @@ -499,10 +503,10 @@ void setUp() { void 대댓글을_삭제하는_경우_부모_댓글이_논리적으로_제거된_상태이며_더이상_존재하는_자식이_없는_경우_부모_댓글도_물리적으로_제거된다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "좋은 글 감사합니다", "비인증", "1234", null); + var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "좋은 글 감사합니다", "비인증", "1234", null); var 댓글_ID = 비인증_댓글_작성(댓글_작성_요청, null); - var 대댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "대댓글입니다", 공개, 댓글_ID); + var 대댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "대댓글입니다", 공개, 댓글_ID); var 대댓글_ID = 댓글_작성(말랑_세션_ID, 대댓글_작성_요청, null); 비인증_댓글_삭제_요청(댓글_ID, "1234", null); @@ -511,7 +515,7 @@ void setUp() { // then 응답_상태를_검증한다(응답, 정상_처리); - var 댓글_조회_응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, null); + var 댓글_조회_응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, 말랑_블로그_이름, null); 특정_포스트의_댓글_전체_조회_응답을_검증한다(댓글_조회_응답, emptyList()); } @@ -524,7 +528,7 @@ class 블로그_주인인_경우 { @Test void 삭제_가능하다() { // given - var 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, "댓글", 비공개, null); + var 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 댓글_ID = 댓글_작성(말랑_세션_ID, 댓글_작성_요청, null); // when @@ -541,7 +545,7 @@ class 블로그_주인이_아닌_경우 { @Test void 입력한_비밀번호가_포스트의_비밀번호와_다르다면_삭제할_수_없다() { // given - var 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, "댓글", 비공개, null); + var 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 댓글_ID = 댓글_작성(동훈_세션_ID, 댓글_작성_요청, "1234"); // when @@ -554,7 +558,7 @@ class 블로그_주인이_아닌_경우 { @Test void 입력한_비밀번호가_포스트의_비밀번호와_일치하면_삭제할_수_있다() { // given - var 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, "댓글", 비공개, null); + var 댓글_작성_요청 = new WriteAuthCommentRequest(보호_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 댓글_ID = 댓글_작성(동훈_세션_ID, 댓글_작성_요청, "1234"); // when @@ -572,7 +576,7 @@ class 비공개_포스트인_경우 { @Test void 블로그_주인은_삭제_가능하다() { // given - var 댓글_작성_요청 = new WriteAuthCommentRequest(비공개_포스트_ID, "댓글", 비공개, null); + var 댓글_작성_요청 = new WriteAuthCommentRequest(비공개_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 댓글_ID = 댓글_작성(말랑_세션_ID, 댓글_작성_요청, null); // when @@ -584,7 +588,7 @@ class 비공개_포스트인_경우 { @Test void 블로그_주인이_아닌_경우_삭제할_수_없다() { - var 댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, "댓글", 비공개, null); + var 댓글_작성_요청 = new WriteAuthCommentRequest(공개_포스트_ID, 말랑_블로그_이름, "댓글", 비공개, null); var 댓글_ID = 댓글_작성(동훈_세션_ID, 댓글_작성_요청, null); 포스트_수정_요청(말랑_세션_ID, 공개_포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); @@ -611,16 +615,16 @@ protected void setUp() { void 로그인하지_않은_경우_비밀_댓글은_비밀_댓글입니다로_처리되어_조회된다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 헤헤_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "헤헤 댓글", "헤헤", "1234", null); - var 동훈_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "동훈 댓글", 공개, null); - var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 동훈 댓글", 비공개, null); + var 헤헤_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "헤헤 댓글", "헤헤", "1234", null); + var 동훈_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "동훈 댓글", 공개, null); + var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 동훈 댓글", 비공개, null); var 헤헤_댓글_ID = 비인증_댓글_작성(헤헤_댓글_작성_요청, null); var 동훈_공개_댓글_ID = 댓글_작성(동훈_세션_ID, 동훈_공개_댓글_작성_요청, null); var 동훈_비밀_댓글_ID = 댓글_작성(동훈_세션_ID, 동훈_비밀_댓글_작성_요청, null); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, null); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, 말랑_블로그_이름, null); // then var 예상_데이터 = List.of( @@ -655,11 +659,11 @@ protected void setUp() { void 로그인한_경우_내가_쓴_비밀_댓글을_포함한_댓글들이_전체_조회된다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 헤헤_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "헤헤 댓글", "헤헤", "1234", null); - var 동훈_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "동훈 댓글", 공개, null); - var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 동훈 댓글", 비공개, null); - var 후후_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "후후 댓글", 공개, null); - var 후후_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 후후 댓글", 비공개, null); + var 헤헤_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "헤헤 댓글", "헤헤", "1234", null); + var 동훈_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "동훈 댓글", 공개, null); + var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 동훈 댓글", 비공개, null); + var 후후_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "후후 댓글", 공개, null); + var 후후_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 후후 댓글", 비공개, null); var 헤헤_댓글_ID = 비인증_댓글_작성(헤헤_댓글_작성_요청, null); var 동훈_공개_댓글_ID = 댓글_작성(동훈_세션_ID, 동훈_공개_댓글_작성_요청, null); @@ -668,7 +672,7 @@ protected void setUp() { var 후후_비밀_댓글_ID = 댓글_작성(후후_세션_ID, 후후_비밀_댓글_작성_요청, null); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, 말랑_블로그_이름, null); // then var 예상_데이터 = List.of( @@ -726,19 +730,19 @@ protected void setUp() { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); var 헤나_세션_ID = 회원가입과_로그인_후_세션_ID_반환("헤나"); - var 동훈_댓글_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 동훈 댓글", 비공개, null); + var 동훈_댓글_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 동훈 댓글", 비공개, null); var 동훈_비공개_댓글_ID = 댓글_작성(동훈_세션_ID, 동훈_댓글_요청, null); - var 헤나_댓글_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 헤나 댓글", 비공개, 동훈_비공개_댓글_ID); - var 후후_댓글_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 후후 댓글", 비공개, 동훈_비공개_댓글_ID); + var 헤나_댓글_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 헤나 댓글", 비공개, 동훈_비공개_댓글_ID); + var 후후_댓글_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 후후 댓글", 비공개, 동훈_비공개_댓글_ID); var 헤나_비밀_댓글_ID = 댓글_작성(헤나_세션_ID, 헤나_댓글_요청, null); var 후후_비밀_댓글_ID = 댓글_작성(후후_세션_ID, 후후_댓글_요청, null); // when - var 댓글_작성자_조회_결과 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, null); - var 대댓글_작성자_조회_결과1 = 특정_포스트의_댓글_전체_조회_요청(헤나_세션_ID, 포스트_ID, null); - var 대댓글_작성자_조회_결과2 = 특정_포스트의_댓글_전체_조회_요청(후후_세션_ID, 포스트_ID, null); + var 댓글_작성자_조회_결과 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, 말랑_블로그_이름, null); + var 대댓글_작성자_조회_결과1 = 특정_포스트의_댓글_전체_조회_요청(헤나_세션_ID, 포스트_ID, 말랑_블로그_이름, null); + var 대댓글_작성자_조회_결과2 = 특정_포스트의_댓글_전체_조회_요청(후후_세션_ID, 포스트_ID, 말랑_블로그_이름, null); // then var 댓글_작성자_예상_데이터 = List.of( @@ -834,21 +838,21 @@ protected void setUp() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 헤헤_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "헤헤 댓글", "헤헤", "1234", null); + var 헤헤_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "헤헤 댓글", "헤헤", "1234", null); var 헤헤_댓글_ID = 비인증_댓글_작성(헤헤_댓글_작성_요청, null); - var 동훈_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "동훈 댓글", 공개, null); - var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 동훈 댓글", 비공개, null); + var 동훈_공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "동훈 댓글", 공개, null); + var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 동훈 댓글", 비공개, null); var 동훈_공개_댓글_ID = 댓글_작성(동훈_세션_ID, 동훈_공개_댓글_작성_요청, null); var 동훈_비밀_댓글_ID = 댓글_작성(동훈_세션_ID, 동훈_비밀_댓글_작성_요청, null); - var 후후공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "후후 댓글", 공개, null); - var 후후_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 후후 댓글", 비공개, null); + var 후후공개_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "후후 댓글", 공개, null); + var 후후_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 후후 댓글", 비공개, null); var 후후_공개_댓글_ID = 댓글_작성(후후_세션_ID, 후후공개_댓글_작성_요청, null); var 후후_비밀_댓글_ID = 댓글_작성(후후_세션_ID, 후후_비밀_댓글_작성_요청, null); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(말랑_세션_ID, 포스트_ID, 말랑_블로그_이름, null); // then var 예상_데이터 = List.of( @@ -904,9 +908,9 @@ protected void setUp() { void 삭제된_댓글은_삭제된_댓글입니다로_처리되어_조회된다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "좋은 글 감사합니다", "비인증 말랑", "1234", null); + var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "좋은 글 감사합니다", "비인증 말랑", "1234", null); var 댓글_ID = 비인증_댓글_작성(댓글_작성_요청, null); - var 대댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "대댓글입니다", 공개, 댓글_ID); + var 대댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "대댓글입니다", 공개, 댓글_ID); var 대댓글_ID = 댓글_작성(말랑_세션_ID, 대댓글_작성_요청, null); 비인증_댓글_삭제_요청(댓글_ID, "1234", null); @@ -915,7 +919,7 @@ protected void setUp() { // then 응답_상태를_검증한다(응답, 정상_처리); - var 댓글_조회_응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, null); + var 댓글_조회_응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_ID, 말랑_블로그_이름, null); 특정_포스트의_댓글_전체_조회_응답을_검증한다(댓글_조회_응답, List.of( new UnAuthCommentResponse( @@ -946,14 +950,14 @@ class 블로그_주인인_경우 { void 조회_가능하다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(말랑_블로그_이름)); - var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "비인증 댓글", "비인증", "1234", null); + var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "비인증 댓글", "비인증", "1234", null); var 비인증_댓글_ID = 비인증_댓글_작성(댓글_작성_요청, "1234"); - var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, "[비밀] 동훈 댓글", 비공개, null); + var 동훈_비밀_댓글_작성_요청 = new WriteAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "[비밀] 동훈 댓글", 비공개, null); var 동훈_비밀_댓글_ID = 댓글_작성(동훈_세션_ID, 동훈_비밀_댓글_작성_요청, "1234"); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(말랑_세션_ID, 포스트_ID, 말랑_블로그_이름, null); // then var 예상_데이터 = List.of( @@ -986,11 +990,11 @@ class 블로그_주인이_아닌_경우 { void 입력한_비밀번호가_포스트의_비밀번호와_다르다면_조회할_수_없다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(말랑_블로그_이름)); - var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "비인증 댓글", "비인증", "1234", null); + var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "비인증 댓글", "비인증", "1234", null); var 비인증_댓글_ID = 비인증_댓글_작성(댓글_작성_요청, "1234"); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, 말랑_블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); @@ -1000,11 +1004,11 @@ class 블로그_주인이_아닌_경우 { void 입력한_비밀번호가_포스트의_비밀번호와_일치하면_조회할_수_있다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(말랑_블로그_이름)); - var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "비인증 댓글", "비인증", "1234", null); + var 댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "비인증 댓글", "비인증", "1234", null); var 비인증_댓글_ID = 비인증_댓글_작성(댓글_작성_요청, "1234"); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, "1234"); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(동훈_세션_ID, 포스트_ID, 말랑_블로그_이름, "1234"); // then var 예상_데이터 = List.of( @@ -1029,12 +1033,12 @@ class 비공개_포스트인_경우 { void 블로그_주인은_조회_가능하다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 비인증_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "비인증 댓글", "헤헤", "1234", null); + var 비인증_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "비인증 댓글", "헤헤", "1234", null); var 비인증_댓글_ID = 비인증_댓글_작성(비인증_댓글_작성_요청, null); 포스트_수정_요청(말랑_세션_ID, 포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(말랑_세션_ID, 포스트_ID, 말랑_블로그_이름, null); // then var 예상_데이터 = List.of( @@ -1053,12 +1057,12 @@ class 비공개_포스트인_경우 { @Test void 블로그_주인이_아닌_경우_조회할_수_없다() { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 비인증_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, "비인증 댓글", "헤헤", "1234", null); + var 비인증_댓글_작성_요청 = new WriteUnAuthCommentRequest(포스트_ID, 말랑_블로그_이름, "비인증 댓글", "헤헤", "1234", null); var 비인증_댓글_ID = 비인증_댓글_작성(비인증_댓글_작성_요청, null); 포스트_수정_요청(말랑_세션_ID, 포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); // when - var 응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_작성자가_아닌_다른_회원_세션_ID, 포스트_ID, null); + var 응답 = 특정_포스트의_댓글_전체_조회_요청(포스트_작성자가_아닌_다른_회원_세션_ID, 포스트_ID, 말랑_블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); diff --git a/src/test/java/com/mallang/acceptance/post/PostAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/post/PostAcceptanceSteps.java index 4392a548..93ed6024 100644 --- a/src/test/java/com/mallang/acceptance/post/PostAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/post/PostAcceptanceSteps.java @@ -24,11 +24,12 @@ public class PostAcceptanceSteps { public static ExtractableResponse 포스트_단일_조회_요청( @Nullable String 세션_ID, Long 포스트_ID, + String 블로그_이름, @Nullable String 비밀번호 ) { return given(세션_ID) .cookie(POST_PASSWORD_COOKIE, 비밀번호) - .get("/posts/{id}", 포스트_ID) + .get("/posts/{blogName}/{id}", 블로그_이름, 포스트_ID) .then().log().all() .extract(); } diff --git a/src/test/java/com/mallang/acceptance/post/PostAcceptanceTest.java b/src/test/java/com/mallang/acceptance/post/PostAcceptanceTest.java index 785d1006..2340250d 100644 --- a/src/test/java/com/mallang/acceptance/post/PostAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/post/PostAcceptanceTest.java @@ -13,9 +13,9 @@ import static com.mallang.acceptance.post.PostAcceptanceSteps.포스트_전체_조회_응답을_검증한다; import static com.mallang.acceptance.post.PostLikeAcceptanceSteps.포스트_좋아요_요청; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_생성; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; @@ -110,7 +110,7 @@ void setUp() { @Test void 포스트를_단일_조회한다() { // when - var 응답 = 포스트_단일_조회_요청(null, 공개_포스트_ID, null); + var 응답 = 포스트_단일_조회_요청(null, 공개_포스트_ID, 말랑_블로그_이름, null); // then PostDetailResponse postDetailResponse = 응답.as(PostDetailResponse.class); @@ -123,7 +123,7 @@ void setUp() { var 없는_ID = 100L; // when - var 응답 = 포스트_단일_조회_요청(null, 없는_ID, null); + var 응답 = 포스트_단일_조회_요청(null, 없는_ID, 말랑_블로그_이름, null); // then 응답_상태를_검증한다(응답, 찾을수_없음); @@ -132,11 +132,11 @@ void setUp() { @Test void 좋아요_눌렀는지_여부가_반영된다() { // given - 포스트_좋아요_요청(말랑_세션_ID, 공개_포스트_ID, null); + 포스트_좋아요_요청(말랑_세션_ID, 공개_포스트_ID, 말랑_블로그_이름, null); // when - var 좋아요_눌린_응답 = 포스트_단일_조회_요청(말랑_세션_ID, 공개_포스트_ID, null); - var 좋아요_안눌린_응답 = 포스트_단일_조회_요청(null, 공개_포스트_ID, null); + var 좋아요_눌린_응답 = 포스트_단일_조회_요청(말랑_세션_ID, 공개_포스트_ID, 말랑_블로그_이름, null); + var 좋아요_안눌린_응답 = 포스트_단일_조회_요청(null, 공개_포스트_ID, 말랑_블로그_이름, null); // then assertThat(좋아요_눌린_응답.as(PostDetailResponse.class).isLiked()).isTrue(); @@ -146,7 +146,7 @@ void setUp() { @Test void 블로그_주인은_비공개_글을_볼_수_있다() { // when - var 응답 = 포스트_단일_조회_요청(말랑_세션_ID, 비공개_포스트_ID, null); + var 응답 = 포스트_단일_조회_요청(말랑_세션_ID, 비공개_포스트_ID, 말랑_블로그_이름, null); // then PostDetailResponse postDetailResponse = 응답.as(PostDetailResponse.class); @@ -157,7 +157,7 @@ void setUp() { @Test void 블로그_주인이_아니라면_비공개_글_조회시_예외() { // when - var 응답 = 포스트_단일_조회_요청(null, 비공개_포스트_ID, null); + var 응답 = 포스트_단일_조회_요청(null, 비공개_포스트_ID, 말랑_블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); @@ -166,7 +166,7 @@ void setUp() { @Test void 블로그_주인은_보호글을_볼_수_있다() { // when - var 응답 = 포스트_단일_조회_요청(말랑_세션_ID, 보호_포스트_ID, null); + var 응답 = 포스트_단일_조회_요청(말랑_세션_ID, 보호_포스트_ID, 말랑_블로그_이름, null); // then PostDetailResponse postDetailResponse = 응답.as(PostDetailResponse.class); @@ -179,12 +179,13 @@ void setUp() { @Test void 블로그_주인이_아닌_경우_보호글_조회시_내용과_썸네일_이미지가_보호된다() { // when - var 응답 = 포스트_단일_조회_요청(null, 보호_포스트_ID, null); + var 응답 = 포스트_단일_조회_요청(null, 보호_포스트_ID, 말랑_블로그_이름, null); // then 포스트_단일_조회_응답을_검증한다(응답, new PostDetailResponse( 보호_포스트_ID, + 말랑_블로그_이름, "[보호] 제목", "보호되어 있는 글입니다. 내용을 보시려면 비밀번호를 입력하세요.", "", @@ -328,6 +329,7 @@ class 포스트_검색_API { var 예상_데이터 = List.of( new PostSearchResponse( 동훈_비공개_포스트_ID, + 동훈_블로그_이름, "[비공개] 동훈 제목", "[비공개] 동훈 내용", "[비공개] 동훈 인트로", @@ -341,6 +343,7 @@ class 포스트_검색_API { ), new PostSearchResponse( 동훈_보호_포스트_ID, + 동훈_블로그_이름, "[보호] 동훈 제목", "[보호] 동훈 내용", "[보호] 동훈 인트로", @@ -354,6 +357,7 @@ class 포스트_검색_API { ), new PostSearchResponse( 동훈_공개_포스트_ID, + 동훈_블로그_이름, "[공개] 동훈 제목", "[공개] 동훈 내용", "[공개] 동훈 인트로", @@ -368,6 +372,7 @@ class 포스트_검색_API { new PostSearchResponse( 말랑_보호_포스트_ID, + 말랑_블로그_이름, "[보호] 말랑 제목", "보호되어 있는 글입니다.", "", @@ -381,6 +386,7 @@ class 포스트_검색_API { ), new PostSearchResponse( 말랑_공개_포스트_ID, + 말랑_블로그_이름, "[공개] 말랑 제목", "[공개] 말랑 내용", "[공개] 말랑 인트로", @@ -587,6 +593,7 @@ class 포스트_검색_API { var 예상 = List.of( new PostSearchResponse( 포스트1_ID, + 말랑_블로그_이름, "포스트", "보호된 글입니다.", "", diff --git a/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceSteps.java index 64434cc2..6acd2e94 100644 --- a/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceSteps.java @@ -12,19 +12,29 @@ @SuppressWarnings("NonAsciiCharacters") public class PostLikeAcceptanceSteps { - public static ExtractableResponse 포스트_좋아요_요청(String 세션_ID, Long 포스트_ID, @Nullable String 비밀번호) { + public static ExtractableResponse 포스트_좋아요_요청( + String 세션_ID, + Long 포스트_ID, + String 블로그_이름, + @Nullable String 비밀번호 + ) { return given(세션_ID) .cookie(POST_PASSWORD_COOKIE, 비밀번호) - .body(new ClickPostLikeRequest(포스트_ID)) + .body(new ClickPostLikeRequest(포스트_ID, 블로그_이름)) .post("/post-likes") .then().log().all() .extract(); } - public static ExtractableResponse 좋아요_취소_요청(String 세션_ID, Long 포스트_ID, @Nullable String 비밀번호) { + public static ExtractableResponse 좋아요_취소_요청( + String 세션_ID, + Long 포스트_ID, + String 블로그_이름, + @Nullable String 비밀번호 + ) { return given(세션_ID) .cookie(POST_PASSWORD_COOKIE, 비밀번호) - .body(new CancelPostLikeRequest(포스트_ID)) + .body(new CancelPostLikeRequest(포스트_ID, 블로그_이름)) .delete("/post-likes") .then().log().all() .extract(); diff --git a/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceTest.java b/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceTest.java index d6ef9feb..03944dc9 100644 --- a/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/post/PostLikeAcceptanceTest.java @@ -17,8 +17,8 @@ import static com.mallang.acceptance.post.PostManageAcceptanceSteps.비공개_포스트_생성_데이터; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_생성; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_수정_요청; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; import static java.util.Collections.emptyList; import com.mallang.acceptance.AcceptanceTest; @@ -47,6 +47,7 @@ protected void setUp() { 말랑_세션_ID = 회원가입과_로그인_후_세션_ID_반환("말랑"); 블로그_이름 = 블로그_개설(말랑_세션_ID, "mallang-log"); 공개_포스트를_보호로_바꾸는_요청 = new UpdatePostRequest( + 블로그_이름, "보호로 변경", "보호", null, @@ -57,6 +58,7 @@ protected void setUp() { emptyList() ); 공개_포스트를_비공개로_바꾸는_요청 = new UpdatePostRequest( + 블로그_이름, "보호로 변경", "보호", null, @@ -77,7 +79,7 @@ class 좋아요_API { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_좋아요_요청(없음(), 포스트_ID, null); + var 응답 = 포스트_좋아요_요청(없음(), 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 인증되지_않음); @@ -89,7 +91,7 @@ class 좋아요_API { var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); // when - var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 생성됨); @@ -99,10 +101,10 @@ class 좋아요_API { void 이미_좋아요를_누른_포스트에는_중복해서_좋아요를_누를_수_없다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); - 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, null); + 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // when - var 응답 = 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 중복됨); @@ -120,7 +122,7 @@ class 블로그_주인인_경우 { var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 생성됨); @@ -137,7 +139,7 @@ class 블로그_주인이_아닌_경우 { var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); // when - var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); @@ -150,7 +152,7 @@ class 블로그_주인이_아닌_경우 { var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); // when - var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, "1234"); + var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, "1234"); // then 응답_상태를_검증한다(응답, 생성됨); @@ -167,7 +169,7 @@ class 비공개_포스트인_경우 { var 포스트_ID = 포스트_생성(말랑_세션_ID, 비공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 생성됨); @@ -180,7 +182,7 @@ class 비공개_포스트인_경우 { var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); // when - var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); @@ -195,10 +197,10 @@ class 좋아요_취소_API { void 좋아요를_취소한다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); - 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, null); + 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // when - var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 본문_없음); @@ -210,7 +212,7 @@ class 좋아요_취소_API { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 찾을수_없음); @@ -226,10 +228,10 @@ class 블로그_주인인_경우 { void 좋아요를_취소할_수_있다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(블로그_이름)); - 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, null); + 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // when - var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 본문_없음); @@ -244,11 +246,11 @@ class 블로그_주인이_아닌_경우 { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); - 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, null); + 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); // when - var 응답 = 좋아요_취소_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 좋아요_취소_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); @@ -259,11 +261,11 @@ class 블로그_주인이_아닌_경우 { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); - 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, null); + 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트_ID, 공개_포스트를_보호로_바꾸는_요청); // when - var 응답 = 좋아요_취소_요청(동훈_세션_ID, 포스트_ID, "1234"); + var 응답 = 좋아요_취소_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, "1234"); // then 응답_상태를_검증한다(응답, 본문_없음); @@ -278,10 +280,10 @@ class 비공개_포스트인_경우 { void 블로그_주인은_취소할_수_있다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 비공개_포스트_생성_데이터(블로그_이름)); - 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, null); + 포스트_좋아요_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // when - var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 좋아요_취소_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 본문_없음); @@ -292,11 +294,11 @@ class 비공개_포스트인_경우 { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); - 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, null); + 포스트_좋아요_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); // when - var 응답 = 좋아요_취소_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 좋아요_취소_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); diff --git a/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceSteps.java index d417aae1..26b8f2ce 100644 --- a/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceSteps.java @@ -3,13 +3,13 @@ import static com.mallang.acceptance.AcceptanceSteps.ID를_추출한다; import static com.mallang.acceptance.AcceptanceSteps.given; import static com.mallang.acceptance.AcceptanceSteps.없음; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import com.mallang.common.presentation.PageResponse; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.presentation.request.CreatePostRequest; import com.mallang.post.presentation.request.DeletePostRequest; import com.mallang.post.presentation.request.UpdatePostRequest; @@ -95,9 +95,9 @@ public class PostManageAcceptanceSteps { .extract(); } - public static ExtractableResponse 포스트_삭제_요청(String 말랑_세션_ID, Long 포스트_ID) { + public static ExtractableResponse 포스트_삭제_요청(String 말랑_세션_ID, Long 포스트_ID, String 블로그_이름) { return given(말랑_세션_ID) - .body(new DeletePostRequest(Arrays.asList(포스트_ID))) + .body(new DeletePostRequest(Arrays.asList(포스트_ID), 블로그_이름)) .delete("/manage/posts") .then() .log().all() @@ -132,9 +132,9 @@ public class PostManageAcceptanceSteps { .isEqualTo(예상_데이터); } - public static ExtractableResponse 내_관리_글_단일_조회_요청(String 세션_ID, Long 포스트_ID) { + public static ExtractableResponse 내_관리_글_단일_조회_요청(String 세션_ID, String 블로그_이름, Long 포스트_ID) { return given(세션_ID) - .get("/manage/posts/{id}", 포스트_ID) + .get("/manage/posts/{blogName}/{id}", 블로그_이름, 포스트_ID) .then() .log().all() .extract(); diff --git a/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceTest.java b/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceTest.java index fe174549..f0eb0a4b 100644 --- a/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/post/PostManageAcceptanceTest.java @@ -9,10 +9,6 @@ import static com.mallang.acceptance.auth.AuthAcceptanceSteps.회원가입과_로그인_후_세션_ID_반환; import static com.mallang.acceptance.blog.BlogAcceptanceSteps.블로그_개설; import static com.mallang.acceptance.category.CategoryAcceptanceSteps.카테고리_생성; -import static com.mallang.acceptance.post.PostAcceptanceSteps.보호되지_않음; -import static com.mallang.acceptance.post.PostAcceptanceSteps.좋아요_안눌림; -import static com.mallang.acceptance.post.PostAcceptanceSteps.포스트_단일_조회_요청; -import static com.mallang.acceptance.post.PostAcceptanceSteps.포스트_단일_조회_응답을_검증한다; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.공개_포스트_생성_데이터; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.내_관리_글_단일_조회_요청; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.내_관리_글_단일_조회_응답을_검증한다; @@ -22,16 +18,14 @@ import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_생성; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_생성_요청; import static com.mallang.acceptance.post.PostManageAcceptanceSteps.포스트_수정_요청; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static java.util.Collections.emptyList; import com.mallang.acceptance.AcceptanceTest; import com.mallang.post.presentation.request.CreatePostRequest; import com.mallang.post.presentation.request.UpdatePostRequest; -import com.mallang.post.query.response.PostDetailResponse; -import com.mallang.post.query.response.PostDetailResponse.WriterResponse; import com.mallang.post.query.response.PostManageDetailResponse; import com.mallang.post.query.response.PostManageDetailResponse.CategoryResponse; import com.mallang.post.query.response.PostManageDetailResponse.TagResponses; @@ -95,7 +89,9 @@ protected void setUp() { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); // when - UpdatePostRequest 포스트_업데이트_요청 = new UpdatePostRequest("업데이트 제목", + UpdatePostRequest 포스트_업데이트_요청 = new UpdatePostRequest( + 말랑_블로그_이름, + "업데이트 제목", "업데이트 내용", "업데이트 포스트 썸네일 이름", "업데이트 인트로", @@ -108,37 +104,18 @@ protected void setUp() { // then 응답_상태를_검증한다(응답, 정상_처리); - var 조회_결과 = 포스트_단일_조회_요청(말랑_세션_ID, 포스트_ID, null); - var 예상_데이터 = new PostDetailResponse( - 포스트_ID, - "업데이트 제목", - "업데이트 내용", - "업데이트 포스트 썸네일 이름", - PRIVATE, - 보호되지_않음, - null, - 0, - 좋아요_안눌림, - null, - new WriterResponse(null, "말랑", "말랑"), - new PostDetailResponse.CategoryResponse(Spring_카테고리_ID, "Spring"), - new PostDetailResponse.TagResponses(List.of("태그1", "태그2")) - ); - 포스트_단일_조회_응답을_검증한다(조회_결과, 예상_데이터); } @Test void 포스트를_삭제한다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(말랑_블로그_이름)); - var 다른_회원_세션_ID = 회원가입과_로그인_후_세션_ID_반환("다른회원"); // when - var 응답 = 포스트_삭제_요청(말랑_세션_ID, 포스트_ID); + var 응답 = 포스트_삭제_요청(말랑_세션_ID, 포스트_ID, 말랑_블로그_이름); // then 응답_상태를_검증한다(응답, 본문_없음); - 응답_상태를_검증한다(포스트_단일_조회_요청(null, 포스트_ID, null), 찾을수_없음); } @Nested @@ -163,7 +140,8 @@ void setUp() { ); public_spring_포스트_ID = 포스트_생성(말랑_세션_ID, public_spring_포스트_요청); - CreatePostRequest protected_jpa_포스트_요청 = new CreatePostRequest(말랑_블로그_이름, + CreatePostRequest protected_jpa_포스트_요청 = new CreatePostRequest( + 말랑_블로그_이름, "Jpa 입니다", "이번에는 이것 저것들에 대해 알아보아요", "썸넬2", @@ -175,7 +153,8 @@ void setUp() { ); protected_jpa_포스트_ID = 포스트_생성(말랑_세션_ID, protected_jpa_포스트_요청); - CreatePostRequest private_front_포스트_요청 = new CreatePostRequest(말랑_블로그_이름, + CreatePostRequest private_front_포스트_요청 = new CreatePostRequest( + 말랑_블로그_이름, "Front 입니다", "잘 알아보았어요!", null, @@ -396,7 +375,7 @@ void setUp() { @Test void 나의_글을_관리용으로_단일_조회한다() { // when - var 응답 = 내_관리_글_단일_조회_요청(말랑_세션_ID, 포스트_ID); + var 응답 = 내_관리_글_단일_조회_요청(말랑_세션_ID, 말랑_블로그_이름, 포스트_ID); // then 내_관리_글_단일_조회_응답을_검증한다(응답, @@ -416,7 +395,7 @@ void setUp() { @Test void 냐의_글이_아닌_경우_예외() { // when - var 응답 = 내_관리_글_단일_조회_요청(동훈_세션_ID, 포스트_ID); + var 응답 = 내_관리_글_단일_조회_요청(동훈_세션_ID, 말랑_블로그_이름, 포스트_ID); // then 응답_상태를_검증한다(응답, 찾을수_없음); diff --git a/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceSteps.java b/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceSteps.java index 33be3a99..5985ec63 100644 --- a/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceSteps.java +++ b/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceSteps.java @@ -12,18 +12,19 @@ @SuppressWarnings("NonAsciiCharacters") public class PostStarAcceptanceSteps { - public static ExtractableResponse 포스트_즐겨찾기_요청(String 세션_ID, Long 포스트_ID, @Nullable String 비밀번호) { + public static ExtractableResponse 포스트_즐겨찾기_요청(String 세션_ID, Long 포스트_ID, String 블로그_이름, + @Nullable String 비밀번호) { return given(세션_ID) .cookie(POST_PASSWORD_COOKIE, 비밀번호) - .body(new StarPostRequest(포스트_ID)) + .body(new StarPostRequest(포스트_ID, 블로그_이름)) .post("/post-stars") .then().log().all() .extract(); } - public static ExtractableResponse 포스트_즐겨찾기_취소_요청(String 세션_ID, Long 포스트_ID) { + public static ExtractableResponse 포스트_즐겨찾기_취소_요청(String 세션_ID, Long 포스트_ID, String 블로그_이름) { return given(세션_ID) - .body(new CancelPostStarRequest(포스트_ID)) + .body(new CancelPostStarRequest(포스트_ID, 블로그_이름)) .delete("/post-stars") .then().log().all() .extract(); diff --git a/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceTest.java b/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceTest.java index c0b39f85..1e4950b8 100644 --- a/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceTest.java +++ b/src/test/java/com/mallang/acceptance/post/PostStarAcceptanceTest.java @@ -19,9 +19,9 @@ import static com.mallang.acceptance.post.PostStarAcceptanceSteps.특정_회원의_즐겨찾기_포스트_목록_조회_요청; import static com.mallang.acceptance.post.PostStarAcceptanceSteps.포스트_즐겨찾기_요청; import static com.mallang.acceptance.post.PostStarAcceptanceSteps.포스트_즐겨찾기_취소_요청; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; @@ -60,6 +60,7 @@ protected void setUp() { 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); 동훈_ID = 내_정보_조회_요청(동훈_세션_ID).as(MemberResponse.class).id(); 공개_포스트를_보호로_바꾸는_요청 = new UpdatePostRequest( + 블로그_이름, "보호로 변경", "공개글에서 보호됨", null, @@ -70,6 +71,7 @@ protected void setUp() { emptyList() ); 공개_포스트를_비공개로_바꾸는_요청 = new UpdatePostRequest( + 블로그_이름, "보호로 변경", "공개글에서 비공개됨", null, @@ -90,7 +92,7 @@ class 즐겨찾기_API { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_요청(없음(), 포스트_ID, null); + var 응답 = 포스트_즐겨찾기_요청(없음(), 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 인증되지_않음); @@ -101,7 +103,7 @@ class 즐겨찾기_API { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 생성됨); @@ -111,10 +113,10 @@ class 즐겨찾기_API { void 이미_즐겨찾기를_누른_포스트에는_중복해서_즐겨찾기를_누를_수_없다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); - 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, null); + 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // when - var 응답 = 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 중복됨); @@ -132,7 +134,7 @@ class 블로그_주인인_경우 { var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 생성됨); @@ -148,7 +150,7 @@ class 블로그_주인이_아닌_경우 { var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); @@ -160,7 +162,7 @@ class 블로그_주인이_아닌_경우 { var 포스트_ID = 포스트_생성(말랑_세션_ID, 보호_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, "1234"); + var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, "1234"); // then 응답_상태를_검증한다(응답, 생성됨); @@ -177,7 +179,7 @@ class 비공개_포스트인_경우 { var 포스트_ID = 포스트_생성(말랑_세션_ID, 비공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, null); + var 응답 = 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 생성됨); @@ -189,7 +191,7 @@ class 비공개_포스트인_경우 { var 포스트_ID = 포스트_생성(말랑_세션_ID, 비공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, null); + var 응답 = 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); // then 응답_상태를_검증한다(응답, 권한_없음); @@ -204,10 +206,10 @@ class 즐겨찾기_취소_API { void 즐겨찾기를_취소한다() { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); - 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, null); + 포스트_즐겨찾기_요청(말랑_세션_ID, 포스트_ID, 블로그_이름, null); // when - var 응답 = 포스트_즐겨찾기_취소_요청(말랑_세션_ID, 포스트_ID); + var 응답 = 포스트_즐겨찾기_취소_요청(말랑_세션_ID, 포스트_ID, 블로그_이름); // then 응답_상태를_검증한다(응답, 본문_없음); @@ -219,7 +221,7 @@ class 즐겨찾기_취소_API { var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); // when - var 응답 = 포스트_즐겨찾기_취소_요청(말랑_세션_ID, 포스트_ID); + var 응답 = 포스트_즐겨찾기_취소_요청(말랑_세션_ID, 포스트_ID, 블로그_이름); // then 응답_상태를_검증한다(응답, 찾을수_없음); @@ -230,11 +232,11 @@ class 즐겨찾기_취소_API { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); // when - var 응답 = 포스트_즐겨찾기_취소_요청(동훈_세션_ID, 포스트_ID); + var 응답 = 포스트_즐겨찾기_취소_요청(동훈_세션_ID, 포스트_ID, 블로그_이름); // then 응답_상태를_검증한다(응답, 본문_없음); @@ -245,11 +247,11 @@ class 즐겨찾기_취소_API { // given var 포스트_ID = 포스트_생성(말랑_세션_ID, 공개_포스트_생성_데이터(블로그_이름)); var 동훈_세션_ID = 회원가입과_로그인_후_세션_ID_반환("동훈"); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트_ID, 공개_포스트를_비공개로_바꾸는_요청); // when - var 응답 = 포스트_즐겨찾기_취소_요청(동훈_세션_ID, 포스트_ID); + var 응답 = 포스트_즐겨찾기_취소_요청(동훈_세션_ID, 포스트_ID, 블로그_이름); // then 응답_상태를_검증한다(응답, 본문_없음); @@ -306,9 +308,9 @@ protected void setUp() { var 포스트1_ID = 포스트_생성(말랑_세션_ID, 포스트1_데이터); var 포스트2_ID = 포스트_생성(말랑_세션_ID, 포스트2_데이터); var 포스트3_ID = 포스트_생성(말랑_세션_ID, 포스트3_데이터); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, 블로그_이름, null); // when var 응답 = 특정_회원의_즐겨찾기_포스트_목록_조회_요청(null, 동훈_ID); @@ -327,9 +329,9 @@ protected void setUp() { var 포스트1_ID = 포스트_생성(말랑_세션_ID, 포스트1_데이터); var 포스트2_ID = 포스트_생성(말랑_세션_ID, 포스트2_데이터); var 포스트3_ID = 포스트_생성(말랑_세션_ID, 포스트3_데이터); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트1_ID, 공개_포스트를_보호로_바꾸는_요청); @@ -350,9 +352,9 @@ protected void setUp() { var 포스트1_ID = 포스트_생성(말랑_세션_ID, 포스트1_데이터); var 포스트2_ID = 포스트_생성(말랑_세션_ID, 포스트2_데이터); var 포스트3_ID = 포스트_생성(말랑_세션_ID, 포스트3_데이터); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트1_ID, 공개_포스트를_보호로_바꾸는_요청); @@ -372,9 +374,9 @@ protected void setUp() { var 포스트1_ID = 포스트_생성(말랑_세션_ID, 포스트1_데이터); var 포스트2_ID = 포스트_생성(말랑_세션_ID, 포스트2_데이터); var 포스트3_ID = 포스트_생성(말랑_세션_ID, 포스트3_데이터); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트1_ID, 공개_포스트를_비공개로_바꾸는_요청); @@ -395,9 +397,9 @@ protected void setUp() { var 포스트1_ID = 포스트_생성(말랑_세션_ID, 포스트1_데이터); var 포스트2_ID = 포스트_생성(말랑_세션_ID, 포스트2_데이터); var 포스트3_ID = 포스트_생성(말랑_세션_ID, 포스트3_데이터); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, null); - 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트1_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트2_ID, 블로그_이름, null); + 포스트_즐겨찾기_요청(동훈_세션_ID, 포스트3_ID, 블로그_이름, null); 포스트_수정_요청(말랑_세션_ID, 포스트1_ID, 공개_포스트를_비공개로_바꾸는_요청); 포스트_수정_요청(말랑_세션_ID, 포스트1_ID, 공개_포스트를_보호로_바꾸는_요청); diff --git a/src/test/java/com/mallang/blog/application/AboutServiceTest.java b/src/test/java/com/mallang/blog/application/AboutServiceTest.java index 862f0089..a576e50f 100644 --- a/src/test/java/com/mallang/blog/application/AboutServiceTest.java +++ b/src/test/java/com/mallang/blog/application/AboutServiceTest.java @@ -2,6 +2,7 @@ import static com.mallang.auth.MemberFixture.동훈; import static com.mallang.auth.MemberFixture.말랑; +import static com.mallang.blog.domain.BlogFixture.mallangBlog; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -31,12 +32,15 @@ class AboutServiceTest extends ServiceTest { private Member member; private Member other; private Blog blog; + private WriteAboutCommand writeAboutCommand; @BeforeEach void setUp() { member = memberRepository.save(말랑()); other = memberRepository.save(동훈()); - blog = blogRepository.save(new Blog("mallang-log", member)); + blog = blogRepository.save(mallangBlog(member)); + writeAboutCommand = + new WriteAboutCommand(member.getId(), blog.getName(), "안녕하세요"); } @Nested @@ -44,24 +48,20 @@ class 소개_작성_시 { @Test void 첫_작성이라면_작성된다() { - // given - WriteAboutCommand command = new WriteAboutCommand(member.getId(), blog.getName(), "안녕하세요"); - // when & then assertDoesNotThrow(() -> { - aboutService.write(command); + aboutService.write(writeAboutCommand); }); } @Test void 블로그에_이미_작성된_소개가_있으면_예외() { // given - WriteAboutCommand command = new WriteAboutCommand(member.getId(), blog.getName(), "안녕하세요"); - aboutService.write(command); + aboutService.write(writeAboutCommand); // when & then assertThatThrownBy(() -> - aboutService.write(command) + aboutService.write(writeAboutCommand) ).isInstanceOf(AlreadyExistAboutException.class); } @@ -84,8 +84,7 @@ class 소개_수정_시 { @BeforeEach void setUp() { - WriteAboutCommand command = new WriteAboutCommand(member.getId(), blog.getName(), "안녕하세요"); - aboutId = aboutService.write(command); + aboutId = aboutService.write(writeAboutCommand); } @Test @@ -120,8 +119,7 @@ class 소개_삭제_시 { @BeforeEach void setUp() { - WriteAboutCommand command = new WriteAboutCommand(member.getId(), blog.getName(), "안녕하세요"); - aboutId = aboutService.write(command); + aboutId = aboutService.write(writeAboutCommand); } @Test diff --git a/src/test/java/com/mallang/blog/application/BlogSubscribeServiceTest.java b/src/test/java/com/mallang/blog/application/BlogSubscribeServiceTest.java index ee23afa7..6147a5a1 100644 --- a/src/test/java/com/mallang/blog/application/BlogSubscribeServiceTest.java +++ b/src/test/java/com/mallang/blog/application/BlogSubscribeServiceTest.java @@ -37,8 +37,11 @@ class 블로그_구독_시 { @Test void 블로그를_구독한다() { + // given + BlogSubscribeCommand command = new BlogSubscribeCommand(mallangId, otherBlogName); + // when - Long subscribeId = blogSubscribeService.subscribe(new BlogSubscribeCommand(mallangId, otherBlogName)); + Long subscribeId = blogSubscribeService.subscribe(command); // then assertThat(blogSubscribeRepository.findById(subscribeId)).isPresent(); @@ -48,21 +51,23 @@ class 블로그_구독_시 { void 자신의_블로그를_구독하면_예외() { // given String mallangBlogName = 블로그_개설(mallangId, "mallang-log"); + BlogSubscribeCommand command = new BlogSubscribeCommand(mallangId, mallangBlogName); // when & then assertThatThrownBy(() -> - blogSubscribeService.subscribe(new BlogSubscribeCommand(mallangId, mallangBlogName)) + blogSubscribeService.subscribe(command) ).isInstanceOf(SelfSubscribeException.class); } @Test void 이미_구독한_블로그라면_예외() { // given - blogSubscribeService.subscribe(new BlogSubscribeCommand(mallangId, otherBlogName)); + BlogSubscribeCommand command = new BlogSubscribeCommand(mallangId, otherBlogName); + blogSubscribeService.subscribe(command); // when & then assertThatThrownBy(() -> - blogSubscribeService.subscribe(new BlogSubscribeCommand(mallangId, otherBlogName)) + blogSubscribeService.subscribe(command) ).isInstanceOf(AlreadySubscribedException.class); } } @@ -73,10 +78,12 @@ class 블로그_구독_취소_시 { @Test void 구독한_블로그를_구독_취소한다() { // given - Long subscribeId = blogSubscribeService.subscribe(new BlogSubscribeCommand(mallangId, otherBlogName)); + BlogSubscribeCommand subscribeCommand = new BlogSubscribeCommand(mallangId, otherBlogName); + Long subscribeId = blogSubscribeService.subscribe(subscribeCommand); + BlogUnsubscribeCommand unsubscribeCommand = new BlogUnsubscribeCommand(mallangId, otherBlogName); // when - blogSubscribeService.unsubscribe(new BlogUnsubscribeCommand(mallangId, otherBlogName)); + blogSubscribeService.unsubscribe(unsubscribeCommand); // then assertThat(blogSubscribeRepository.findById(subscribeId)).isEmpty(); @@ -84,9 +91,12 @@ class 블로그_구독_취소_시 { @Test void 구독하지_않은_블로그라면_예외() { + // given + BlogUnsubscribeCommand command = new BlogUnsubscribeCommand(mallangId, otherBlogName); + // when & then assertThatThrownBy(() -> - blogSubscribeService.unsubscribe(new BlogUnsubscribeCommand(mallangId, otherBlogName)) + blogSubscribeService.unsubscribe(command) ).isInstanceOf(UnsubscribeUnsubscribedBlogException.class); } } diff --git a/src/test/java/com/mallang/blog/domain/AboutTest.java b/src/test/java/com/mallang/blog/domain/AboutTest.java index aa77b7f5..a80ec116 100644 --- a/src/test/java/com/mallang/blog/domain/AboutTest.java +++ b/src/test/java/com/mallang/blog/domain/AboutTest.java @@ -1,6 +1,7 @@ package com.mallang.blog.domain; -import static com.mallang.auth.MemberFixture.동훈; +import static com.mallang.auth.MemberFixture.말랑; +import static com.mallang.blog.domain.BlogFixture.mallangBlog; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -21,11 +22,8 @@ class AboutTest { private final AboutValidator aboutValidator = mock(AboutValidator.class); - private final Member member = 동훈(); - private final Blog blog = Blog.builder() - .name("mallang") - .owner(member) - .build(); + private final Member member = 말랑(); + private final Blog blog = mallangBlog(말랑()); @Nested class 작성_시 { diff --git a/src/test/java/com/mallang/blog/domain/BlogFixture.java b/src/test/java/com/mallang/blog/domain/BlogFixture.java new file mode 100644 index 00000000..dbeee7be --- /dev/null +++ b/src/test/java/com/mallang/blog/domain/BlogFixture.java @@ -0,0 +1,22 @@ +package com.mallang.blog.domain; + +import com.mallang.auth.domain.Member; +import org.springframework.test.util.ReflectionTestUtils; + +public class BlogFixture { + + public static final String MALLANG_BLOG_NAME = "mallang-log"; + + public static Blog mallangBlog(Member owner) { + return mallangBlog(null, owner); + } + + public static Blog mallangBlog(Long id, Member owner) { + Blog blog = Blog.builder() + .name(MALLANG_BLOG_NAME) + .owner(owner) + .build(); + ReflectionTestUtils.setField(blog, "id", id); + return blog; + } +} diff --git a/src/test/java/com/mallang/blog/domain/BlogTest.java b/src/test/java/com/mallang/blog/domain/BlogTest.java index 44db5134..fc321646 100644 --- a/src/test/java/com/mallang/blog/domain/BlogTest.java +++ b/src/test/java/com/mallang/blog/domain/BlogTest.java @@ -1,6 +1,7 @@ package com.mallang.blog.domain; -import static com.mallang.auth.MemberFixture.동훈; +import static com.mallang.auth.MemberFixture.말랑; +import static com.mallang.blog.domain.BlogFixture.mallangBlog; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; @@ -25,10 +26,7 @@ class BlogTest { class 개설_시 { private final BlogValidator blogValidator = mock(BlogValidator.class); - private final Blog blog = Blog.builder() - .name("mallang") - .owner(동훈()) - .build(); + private final Blog blog = mallangBlog(말랑()); @Test void 블로그를_생성하려는_회원이_이미_다른_블로그를_가지고_있으면_예외() { diff --git a/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeTest.java b/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeTest.java index 0d5455d4..aae28449 100644 --- a/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeTest.java +++ b/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeTest.java @@ -1,11 +1,12 @@ package com.mallang.blog.domain.subscribe; +import static com.mallang.auth.MemberFixture.말랑; +import static com.mallang.auth.MemberFixture.회원; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.mock; -import com.mallang.auth.MemberFixture; import com.mallang.auth.domain.Member; import com.mallang.blog.domain.Blog; import com.mallang.blog.exception.AlreadySubscribedException; @@ -22,8 +23,8 @@ class BlogSubscribeTest { private final BlogSubscribeValidator blogSubscribeValidator = mock(BlogSubscribeValidator.class); - private final Member member = MemberFixture.말랑(); - private final Member other = MemberFixture.회원("other"); + private final Member member = 말랑(); + private final Member other = 회원("other"); private final Blog mallangBlog = new Blog("mallang-log", member); @Nested diff --git a/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeValidatorTest.java b/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeValidatorTest.java index 155765d0..191b2006 100644 --- a/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeValidatorTest.java +++ b/src/test/java/com/mallang/blog/domain/subscribe/BlogSubscribeValidatorTest.java @@ -1,12 +1,13 @@ package com.mallang.blog.domain.subscribe; +import static com.mallang.auth.MemberFixture.말랑; +import static com.mallang.auth.MemberFixture.회원; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import com.mallang.auth.MemberFixture; import com.mallang.auth.domain.Member; import com.mallang.blog.domain.Blog; import com.mallang.blog.exception.AlreadySubscribedException; @@ -24,8 +25,8 @@ class BlogSubscribeValidatorTest { private final BlogSubscribeRepository blogSubscribeRepository = mock(BlogSubscribeRepository.class); private final BlogSubscribeValidator blogSubscribeValidator = new BlogSubscribeValidator(blogSubscribeRepository); - private final Member member = MemberFixture.말랑(1L); - private final Member other = MemberFixture.회원(2L, "other"); + private final Member member = 말랑(1L); + private final Member other = 회원(2L, "other"); private final Blog mallangBlog = new Blog("mallang-log", member); @Nested diff --git a/src/test/java/com/mallang/comment/application/CommentEventHandlerTest.java b/src/test/java/com/mallang/comment/application/CommentEventHandlerTest.java index 21f34a6d..c85b2d30 100644 --- a/src/test/java/com/mallang/comment/application/CommentEventHandlerTest.java +++ b/src/test/java/com/mallang/comment/application/CommentEventHandlerTest.java @@ -5,6 +5,7 @@ import com.mallang.comment.domain.Comment; import com.mallang.common.ServiceTest; import com.mallang.post.domain.PostDeleteEvent; +import com.mallang.post.domain.PostId; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; @@ -24,16 +25,16 @@ class 포스트_삭제_이벤트를_받아 { void 해당_포스트에_달린_댓글들을_모두_제거한다() { // given Long memberId = 회원을_저장한다("말랑"); - Long otherMemberId = 회원을_저장한다("ohter"); + Long otherMemberId = 회원을_저장한다("other"); String blogName = 블로그_개설(memberId, "mallang-log"); - Long postId1 = 포스트를_저장한다(memberId, blogName, "제목", "내용"); - Long postId2 = 포스트를_저장한다(memberId, blogName, "제목2", "내용1"); - Long post1Comment1 = 댓글을_작성한다(postId1, "댓1", true, otherMemberId); - 대댓글을_작성한다(postId1, "댓1", true, memberId, post1Comment1); - 비인증_대댓글을_작성한다(postId1, "댓1", "익1", "1234", post1Comment1); - 비인증_댓글을_작성한다(postId1, "댓1", "익2", "12345"); + PostId postId1 = 포스트를_저장한다(memberId, blogName, "제목", "내용"); + PostId postId2 = 포스트를_저장한다(memberId, blogName, "제목2", "내용1"); + Long post1Comment1 = 댓글을_작성한다(postId1.getId(), blogName, "댓1", true, otherMemberId); + 대댓글을_작성한다(postId1.getId(), blogName, "댓1", true, memberId, post1Comment1); + 비인증_대댓글을_작성한다(postId1.getId(), blogName, "댓1", "익1", "1234", post1Comment1); + 비인증_댓글을_작성한다(postId1.getId(), blogName, "댓1", "익2", "12345"); - 댓글을_작성한다(postId2, "댓1", true, otherMemberId); // no delete + 댓글을_작성한다(postId2.getId(), blogName, "댓1", true, otherMemberId); // no delete // when publisher.publishEvent(new PostDeleteEvent(postId1)); @@ -41,7 +42,7 @@ class 포스트_삭제_이벤트를_받아 { // then List all = commentRepository.findAll(); boolean nonDeleteCommentExist = all.stream() - .anyMatch(it -> (it.getPost().getId().equals(postId1))); + .anyMatch(it -> (it.getPost().getPostId().equals(postId1))); assertThat(nonDeleteCommentExist).isFalse(); } } diff --git a/src/test/java/com/mallang/comment/application/CommentServiceTest.java b/src/test/java/com/mallang/comment/application/CommentServiceTest.java index 079fb1e2..53308f4a 100644 --- a/src/test/java/com/mallang/comment/application/CommentServiceTest.java +++ b/src/test/java/com/mallang/comment/application/CommentServiceTest.java @@ -16,6 +16,7 @@ import com.mallang.comment.exception.NoAuthorityForCommentException; import com.mallang.comment.exception.NotFoundCommentException; import com.mallang.common.ServiceTest; +import com.mallang.post.domain.PostId; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; @@ -32,7 +33,7 @@ class CommentServiceTest extends ServiceTest { private Long other1Id; private Long other2Id; private String blogName; - private Long postId; + private PostId postId; @BeforeEach void setUp() { @@ -50,7 +51,8 @@ class 댓글_작성_시 { void 로그인한_사용자가_댓글을_작성한다() { // given WriteAuthCommentCommand command = WriteAuthCommentCommand.builder() - .postId(postId) + .postId(postId.getId()) + .blogName(blogName) .content("댓글입니다.") .memberId(other1Id) .secret(false) @@ -67,7 +69,8 @@ class 댓글_작성_시 { void 로그인한_사용자는_비밀_댓글_작성이_가능하다() { // given WriteAuthCommentCommand command = WriteAuthCommentCommand.builder() - .postId(postId) + .postId(postId.getId()) + .blogName(blogName) .content("댓글입니다.") .memberId(other1Id) .secret(true) @@ -84,7 +87,8 @@ class 댓글_작성_시 { void 로그인하지_않은_사용자도_댓글을_달_수_있다() { // given WriteUnAuthCommentCommand command = WriteUnAuthCommentCommand.builder() - .postId(postId) + .postId(postId.getId()) + .blogName(blogName) .content("댓글입니다.") .nickname("비인증1") .password("1234") @@ -100,9 +104,10 @@ class 댓글_작성_시 { @Test void 대댓글을_작성할_수_있다() { // given - Long 말랑_댓글_ID = 댓글을_작성한다(postId, "말랑 댓글", false, postWriterId); + Long 말랑_댓글_ID = 댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", false, postWriterId); WriteUnAuthCommentCommand command = WriteUnAuthCommentCommand.builder() - .postId(postId) + .postId(postId.getId()) + .blogName(blogName) .content("대댓글입니다.") .nickname("비인증1") .password("1234") @@ -125,9 +130,10 @@ class 댓글_작성_시 { @Test void 다른_사람의_댓글에_대댓글을_달_수_있다() { // given - Long 말랑_댓글_ID = 댓글을_작성한다(postId, "말랑 댓글", true, postWriterId); + Long 말랑_댓글_ID = 댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", true, postWriterId); WriteAuthCommentCommand command = WriteAuthCommentCommand.builder() - .postId(postId) + .postId(postId.getId()) + .blogName(blogName) .content("대댓글입니다.") .memberId(other1Id) .parentCommentId(말랑_댓글_ID) @@ -149,10 +155,11 @@ class 댓글_작성_시 { @Test void 대댓글에_대해서는_댓글을_달_수_없다() { // given - Long 말랑_댓글_ID = 댓글을_작성한다(postId, "말랑 댓글", true, postWriterId); - Long 대댓글_ID = 대댓글을_작성한다(postId, "대댓글", false, postWriterId, 말랑_댓글_ID); + Long 말랑_댓글_ID = 댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", true, postWriterId); + Long 대댓글_ID = 대댓글을_작성한다(postId.getId(), blogName, "대댓글", false, postWriterId, 말랑_댓글_ID); WriteAuthCommentCommand command = WriteAuthCommentCommand.builder() - .postId(postId) + .postId(postId.getId()) + .blogName(blogName) .content("대댓글입니다.") .memberId(postWriterId) .parentCommentId(대댓글_ID) @@ -173,10 +180,11 @@ class 댓글_작성_시 { @Test void 대댓글을_다는_경우_부모_댓글과_Post_가_다르면_예외() { // given - Long 포스트2_ID = 포스트를_저장한다(postWriterId, blogName, "포스트2", "내용"); - Long 말랑_댓글_ID = 댓글을_작성한다(postId, "말랑 댓글", true, postWriterId); + PostId 포스트2_ID = 포스트를_저장한다(postWriterId, blogName, "포스트2", "내용"); + Long 말랑_댓글_ID = 댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", true, postWriterId); WriteAuthCommentCommand command = WriteAuthCommentCommand.builder() - .postId(포스트2_ID) + .postId(포스트2_ID.getId()) + .blogName(blogName) .content("대댓글입니다.") .memberId(postWriterId) .parentCommentId(말랑_댓글_ID) @@ -201,7 +209,7 @@ class 댓글_수정_시 { @Test void 댓글이_수정된다() { // given - Long commentId = 댓글을_작성한다(postId, "댓글", false, other1Id); + Long commentId = 댓글을_작성한다(postId.getId(), blogName, "댓글", false, other1Id); UpdateAuthCommentCommand command = UpdateAuthCommentCommand.builder() .commentId(commentId) .content("수정") @@ -220,7 +228,7 @@ class 댓글_수정_시 { @Test void 인증된_사용자의_경우_비공개_여부도_수정할_수_있다() { // given - Long commentId = 댓글을_작성한다(postId, "댓글", false, other1Id); + Long commentId = 댓글을_작성한다(postId.getId(), blogName, "댓글", false, other1Id); UpdateAuthCommentCommand command = UpdateAuthCommentCommand.builder() .commentId(commentId) .content("수정") @@ -240,7 +248,7 @@ class 댓글_수정_시 { @Test void 자신의_댓글이_아닌_경우_예외() { // given - Long commentId = 댓글을_작성한다(postId, "댓글", false, other1Id); + Long commentId = 댓글을_작성한다(postId.getId(), blogName, "댓글", false, other1Id); UpdateAuthCommentCommand command = UpdateAuthCommentCommand.builder() .commentId(commentId) .content("수정") @@ -262,7 +270,7 @@ class 댓글_수정_시 { @Test void 비인증_댓글은_비밀번호가_일치하면_수정할_수_있다() { // given - Long commentId = 비인증_댓글을_작성한다(postId, "댓글", "mal", "1234"); + Long commentId = 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글", "mal", "1234"); UpdateUnAuthCommentCommand command = UpdateUnAuthCommentCommand.builder() .commentId(commentId) .content("수정") @@ -280,7 +288,7 @@ class 댓글_수정_시 { @Test void 비인증_댓글_수정_시_비밀번호가_틀리면_예외() { // given - Long commentId = 비인증_댓글을_작성한다(postId, "댓글", "mal", "1234"); + Long commentId = 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글", "mal", "1234"); UpdateUnAuthCommentCommand command = UpdateUnAuthCommentCommand.builder() .commentId(commentId) .content("수정") @@ -300,7 +308,7 @@ class 댓글_수정_시 { @Test void 포스트_주인도_댓글을_수정할수는_없다() { // given - Long commentId = 댓글을_작성한다(postId, "댓글", false, other1Id); + Long commentId = 댓글을_작성한다(postId.getId(), blogName, "댓글", false, other1Id); UpdateAuthCommentCommand command = UpdateAuthCommentCommand.builder() .commentId(commentId) .content("수정") @@ -326,8 +334,8 @@ class 댓글_제거_시 { @Test void 댓글_작성자는_자신의_댓글을_제거할_수_있다() { // given - Long commentId = 댓글을_작성한다(postId, "댓글", false, - postWriterId); + Long commentId = 댓글을_작성한다( + postId.getId(), blogName, "댓글", false, postWriterId); DeleteAuthCommentCommand command = DeleteAuthCommentCommand.builder() .commentId(commentId) .memberId(postWriterId) @@ -345,7 +353,7 @@ class 댓글_제거_시 { @Test void 자신의_댓글이_아닌_경우_예외() { // given - Long commentId = 댓글을_작성한다(postId, "댓글", false, postWriterId); + Long commentId = 댓글을_작성한다(postId.getId(), blogName, "댓글", false, postWriterId); DeleteAuthCommentCommand command = DeleteAuthCommentCommand.builder() .commentId(commentId) .memberId(other1Id) @@ -364,7 +372,7 @@ class 댓글_제거_시 { @Test void 비인증_댓글은_비밀번호가_일치하면_제거할_수_있다() { // given - Long commentId = 비인증_댓글을_작성한다(postId, "댓글", "mal", "1234"); + Long commentId = 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글", "mal", "1234"); DeleteUnAuthCommentCommand command = DeleteUnAuthCommentCommand.builder() .commentId(commentId) .password("1234") @@ -382,7 +390,7 @@ class 댓글_제거_시 { @Test void 비인증_댓글은_비밀번호가_일치하지_않다면_제거할_수_없다() { // given - Long commentId = 비인증_댓글을_작성한다(postId, "댓글", "mal", "1234"); + Long commentId = 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글", "mal", "1234"); DeleteUnAuthCommentCommand command = DeleteUnAuthCommentCommand.builder() .commentId(commentId) .password("12345") @@ -401,8 +409,8 @@ class 댓글_제거_시 { @Test void 포스트_작성자는_모든_댓글을_제거할_수_있다() { // given - Long comment1Id = 댓글을_작성한다(postId, "댓글", false, other1Id); - Long comment2Id = 비인증_댓글을_작성한다(postId, "댓글", "mal", "1234"); + Long comment1Id = 댓글을_작성한다(postId.getId(), blogName, "댓글", false, other1Id); + Long comment2Id = 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글", "mal", "1234"); DeleteAuthCommentCommand command1 = DeleteAuthCommentCommand.builder() .commentId(comment1Id) .memberId(postWriterId) @@ -428,8 +436,8 @@ class 댓글_제거_시 { @Test void 대댓글_제거_시_부모_댓글과의_관계도_끊어진다() { // given - Long 말랑_댓글_ID = 댓글을_작성한다(postId, "말랑 댓글", false, postWriterId); - Long 대댓글_ID = 비인증_대댓글을_작성한다(postId, "대댓글", "hi", "12", 말랑_댓글_ID); + Long 말랑_댓글_ID = 댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", false, postWriterId); + Long 대댓글_ID = 비인증_대댓글을_작성한다(postId.getId(), blogName, "대댓글", "hi", "12", 말랑_댓글_ID); DeleteUnAuthCommentCommand command = DeleteUnAuthCommentCommand.builder() .commentId(대댓글_ID) .password("12") @@ -451,8 +459,8 @@ class 댓글_제거_시 { @Test void 대댓글을_삭제하는_경우_부모_댓글이_논리적으로_제거된_상태가_아닌_경우_부모는_변함없다() { // given - Long 댓글_ID = 비인증_댓글을_작성한다(postId, "말랑 댓글", "hi", "1"); - Long 대댓글_ID = 비인증_댓글을_작성한다(postId, "대댓글", "hi2", "12"); + Long 댓글_ID = 비인증_댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", "hi", "1"); + Long 대댓글_ID = 비인증_댓글을_작성한다(postId.getId(), blogName, "대댓글", "hi2", "12"); DeleteUnAuthCommentCommand command = DeleteUnAuthCommentCommand.builder() .commentId(대댓글_ID) .password("12") @@ -474,8 +482,8 @@ class 댓글_제거_시 { @Test void 댓글_제거_시_자식_댓글이_존재한다면_부모와의_연관관계는_유지되며_논리적으로만_제거시킨다() { // given - Long 댓글_ID = 비인증_댓글을_작성한다(postId, "말랑 댓글", "hi", "1"); - Long 대댓글_ID = 대댓글을_작성한다(postId, "대댓글", false, postWriterId, + Long 댓글_ID = 비인증_댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", "hi", "1"); + Long 대댓글_ID = 대댓글을_작성한다(postId.getId(), blogName, "대댓글", false, postWriterId, 댓글_ID); DeleteUnAuthCommentCommand command = DeleteUnAuthCommentCommand.builder() .commentId(댓글_ID) @@ -499,8 +507,8 @@ class 댓글_제거_시 { @Test void 대댓글을_삭제하는_경우_부모_댓글이_논리적으로_제거된_상태이며_더이상_존재하는_자식이_없는_경우_부모_댓글도_물리적으로_제거된다() { // given - Long 댓글_ID = 비인증_댓글을_작성한다(postId, "말랑 댓글", "hi", "12"); - Long 대댓글_ID = 비인증_대댓글을_작성한다(postId, "대댓글", "hi2", "12", 댓글_ID); + Long 댓글_ID = 비인증_댓글을_작성한다(postId.getId(), blogName, "말랑 댓글", "hi", "12"); + Long 대댓글_ID = 비인증_대댓글을_작성한다(postId.getId(), blogName, "대댓글", "hi2", "12", 댓글_ID); unAuthCommentService.delete(new DeleteUnAuthCommentCommand(댓글_ID, "12", null, null)); DeleteUnAuthCommentCommand command = DeleteUnAuthCommentCommand.builder() .commentId(대댓글_ID) diff --git a/src/test/java/com/mallang/comment/domain/AuthCommentTest.java b/src/test/java/com/mallang/comment/domain/AuthCommentTest.java index c8780f7e..04328f5f 100644 --- a/src/test/java/com/mallang/comment/domain/AuthCommentTest.java +++ b/src/test/java/com/mallang/comment/domain/AuthCommentTest.java @@ -3,8 +3,8 @@ import static com.mallang.auth.MemberFixture.동훈; import static com.mallang.auth.MemberFixture.말랑; import static com.mallang.auth.MemberFixture.회원; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -15,8 +15,8 @@ import com.mallang.comment.domain.service.CommentDeleteService; import com.mallang.comment.exception.NoAuthorityForCommentException; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.exception.NoAuthorityAccessPostException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; @@ -36,7 +36,6 @@ class AuthCommentTest { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(Visibility.PUBLIC, null)) - .blog(blog) .build(); private final Member member = 말랑(1L); private final Member other = 동훈(2L); @@ -107,7 +106,6 @@ class 보호_포스트에_작성하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -167,7 +165,6 @@ class 비공개_포스트에_작성하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); @Test @@ -291,7 +288,6 @@ class 보호_포스트의_댓글을_수정하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -352,7 +348,6 @@ class 비공개_포스트의_댓글을_수정하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); @Test @@ -479,7 +474,6 @@ class 보호_포스트의_댓글을_삭제하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -537,7 +531,6 @@ class 비공개_포스트의_댓글을_삭제하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); @Test diff --git a/src/test/java/com/mallang/comment/domain/CommentTest.java b/src/test/java/com/mallang/comment/domain/CommentTest.java index f5a3c115..14232fc0 100644 --- a/src/test/java/com/mallang/comment/domain/CommentTest.java +++ b/src/test/java/com/mallang/comment/domain/CommentTest.java @@ -14,8 +14,8 @@ import com.mallang.comment.domain.service.CommentDeleteService; import com.mallang.comment.exception.CommentDepthConstraintViolationException; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -32,7 +32,6 @@ class CommentTest { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(Visibility.PUBLIC, null)) - .blog(blog) .build(); private final Member member = 말랑(1L); private final Member other = 동훈(2L); diff --git a/src/test/java/com/mallang/comment/domain/UnAuthCommentTest.java b/src/test/java/com/mallang/comment/domain/UnAuthCommentTest.java index fab97150..6597a298 100644 --- a/src/test/java/com/mallang/comment/domain/UnAuthCommentTest.java +++ b/src/test/java/com/mallang/comment/domain/UnAuthCommentTest.java @@ -1,9 +1,9 @@ package com.mallang.comment.domain; import static com.mallang.auth.MemberFixture.회원; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -14,7 +14,7 @@ import com.mallang.comment.domain.service.CommentDeleteService; import com.mallang.comment.exception.NoAuthorityForCommentException; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import com.mallang.post.exception.NoAuthorityAccessPostException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; @@ -32,7 +32,6 @@ class UnAuthCommentTest { private final Post post = Post.builder() .visibilityPolish(new PostVisibilityPolicy(PUBLIC, null)) .writer(postWriter) - .blog(blog) .build(); @Nested @@ -80,7 +79,6 @@ class 보호_포스트에_작성하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -123,7 +121,6 @@ class 비공개_포스트에_작성하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); @Test @@ -186,7 +183,6 @@ class 보호_포스트의_댓글을_수정하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -230,7 +226,6 @@ class 비공개_포스트의_댓글을_수정하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); @Test @@ -312,7 +307,6 @@ class 보호_포스트의_댓글을_삭제하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -370,7 +364,6 @@ class 비공개_포스트의_댓글을_삭제하는_경우 { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); @Test diff --git a/src/test/java/com/mallang/comment/domain/service/CommentDeleteServiceTest.java b/src/test/java/com/mallang/comment/domain/service/CommentDeleteServiceTest.java index 498784bf..72a93bbd 100644 --- a/src/test/java/com/mallang/comment/domain/service/CommentDeleteServiceTest.java +++ b/src/test/java/com/mallang/comment/domain/service/CommentDeleteServiceTest.java @@ -12,8 +12,8 @@ import com.mallang.comment.domain.CommentRepository; import com.mallang.comment.domain.UnAuthComment; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; @@ -36,7 +36,6 @@ class CommentDeleteServiceTest { private final Post post = Post.builder() .writer(postWriter) .visibilityPolish(new PostVisibilityPolicy(Visibility.PUBLIC, null)) - .blog(blog) .build(); private final Member member = 말랑(1L); diff --git a/src/test/java/com/mallang/comment/query/CommentQueryServiceTest.java b/src/test/java/com/mallang/comment/query/CommentQueryServiceTest.java index 4b3cd9fd..b7f74554 100644 --- a/src/test/java/com/mallang/comment/query/CommentQueryServiceTest.java +++ b/src/test/java/com/mallang/comment/query/CommentQueryServiceTest.java @@ -6,6 +6,7 @@ import com.mallang.comment.query.response.CommentResponse; import com.mallang.comment.query.response.UnAuthCommentResponse; import com.mallang.common.ServiceTest; +import com.mallang.post.domain.PostId; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -21,7 +22,7 @@ class CommentQueryServiceTest extends ServiceTest { private Long memberId; private String blogName; - private Long postId; + private PostId postId; @Nested class 특정_포스트의_댓글_모두_조회_시 { @@ -36,12 +37,12 @@ void setUp() { @Test void 인증되지_않은_요청인_경우_비밀_댓글은_비밀_댓글로_조회된다() { // given - 댓글을_작성한다(postId, "댓글1", false, memberId); - 댓글을_작성한다(postId, "[비밀] 댓글2", true, memberId); - 비인증_댓글을_작성한다(postId, "댓글3", "랑말", "1234"); + 댓글을_작성한다(postId.getId(), blogName, "댓글1", false, memberId); + 댓글을_작성한다(postId.getId(), blogName, "[비밀] 댓글2", true, memberId); + 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글3", "랑말", "1234"); // when - List result = commentQueryService.findAllByPostId(postId, null, null); + List result = commentQueryService.findAllByPost(postId.getId(), blogName, null, null); // then assertThat(result) @@ -64,14 +65,14 @@ void setUp() { // given Long dong = 회원을_저장한다("동훈"); Long hehe = 회원을_저장한다("헤헤"); - 댓글을_작성한다(postId, "동훈 댓글", false, dong); - 댓글을_작성한다(postId, "헤헤 댓글", false, hehe); - 댓글을_작성한다(postId, "[비밀] 동훈 댓글2", true, dong); // 제외 - 댓글을_작성한다(postId, "[비밀] 헤헤 댓글2", true, hehe); - 비인증_댓글을_작성한다(postId, "댓글3", "랑말", "1234"); + 댓글을_작성한다(postId.getId(), blogName, "동훈 댓글", false, dong); + 댓글을_작성한다(postId.getId(), blogName, "헤헤 댓글", false, hehe); + 댓글을_작성한다(postId.getId(), blogName, "[비밀] 동훈 댓글2", true, dong); // 제외 + 댓글을_작성한다(postId.getId(), blogName, "[비밀] 헤헤 댓글2", true, hehe); + 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글3", "랑말", "1234"); // when - List result = commentQueryService.findAllByPostId(postId, dong, null); + List result = commentQueryService.findAllByPost(postId.getId(), blogName, dong, null); // then assertThat(result) @@ -84,14 +85,14 @@ void setUp() { // given Long dong = 회원을_저장한다("동훈"); Long hehe = 회원을_저장한다("헤헤"); - 댓글을_작성한다(postId, "동훈 댓글", false, memberId); - 댓글을_작성한다(postId, "헤헤 댓글", false, hehe); - 댓글을_작성한다(postId, "[비밀] 동훈 댓글2", true, memberId); // 제외 - 댓글을_작성한다(postId, "[비밀] 헤헤 댓글2", true, hehe); - 비인증_댓글을_작성한다(postId, "댓글3", "랑말", "1234"); + 댓글을_작성한다(postId.getId(), blogName, "동훈 댓글", false, memberId); + 댓글을_작성한다(postId.getId(), blogName, "헤헤 댓글", false, hehe); + 댓글을_작성한다(postId.getId(), blogName, "[비밀] 동훈 댓글2", true, memberId); // 제외 + 댓글을_작성한다(postId.getId(), blogName, "[비밀] 헤헤 댓글2", true, hehe); + 비인증_댓글을_작성한다(postId.getId(), blogName, "댓글3", "랑말", "1234"); // when - List result = commentQueryService.findAllByPostId(postId, memberId, null); + List result = commentQueryService.findAllByPost(postId.getId(), blogName, memberId, null); // then assertThat(result) diff --git a/src/test/java/com/mallang/comment/query/CommentResponsePostProcessorTest.java b/src/test/java/com/mallang/comment/query/CommentResponsePostProcessorTest.java index 667ac8fb..62a96388 100644 --- a/src/test/java/com/mallang/comment/query/CommentResponsePostProcessorTest.java +++ b/src/test/java/com/mallang/comment/query/CommentResponsePostProcessorTest.java @@ -2,6 +2,7 @@ import static com.mallang.auth.MemberFixture.동훈; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -66,7 +67,7 @@ class 비공개_댓글들_처리_시 { // given Post post = mock(Post.class); given(post.getWriter()).willReturn(동훈(1L)); - given(postRepository.getById(1L)).willReturn(post); + given(postRepository.getByIdAndBlogName(any(), any())).willReturn(post); List commentResponses = List.of( AuthCommentResponse.builder() .content("비공개 댓글") @@ -92,7 +93,8 @@ class 비공개_댓글들_처리_시 { ); // when - List commentData = commentDataPostProcessor.processSecret(commentResponses, 1L, 1L); + List commentData = commentDataPostProcessor.processSecret(commentResponses, 1L, "blog", + 1L); // then assertThat(commentData) @@ -108,7 +110,7 @@ class 비공개_댓글들_처리_시 { // given Post post = mock(Post.class); given(post.getWriter()).willReturn(동훈(1L)); - given(postRepository.getById(1L)).willReturn(post); + given(postRepository.getByIdAndBlogName(any(), any())).willReturn(post); List commentResponses = List.of( AuthCommentResponse.builder() .content("비공개 댓글") @@ -139,7 +141,8 @@ class 비공개_댓글들_처리_시 { ); // when - List commentData = commentDataPostProcessor.processSecret(commentResponses, 1L, null); + List commentData = commentDataPostProcessor + .processSecret(commentResponses, 1L, "blog", null); // then assertThat(commentData) @@ -155,7 +158,7 @@ class 비공개_댓글들_처리_시 { // given Post post = mock(Post.class); given(post.getWriter()).willReturn(동훈(1L)); - given(postRepository.getById(1L)).willReturn(post); + given(postRepository.getByIdAndBlogName(any(), any())).willReturn(post); List commentResponses = List.of( AuthCommentResponse.builder() .content("비공개 댓글1") @@ -186,7 +189,8 @@ class 비공개_댓글들_처리_시 { ); // when - List commentData = commentDataPostProcessor.processSecret(commentResponses, 1L, 2L); + List commentData = commentDataPostProcessor + .processSecret(commentResponses, 1L, "blog", 2L); // then assertThat(commentData) diff --git a/src/test/java/com/mallang/comment/query/CommentResponseValidatorTest.java b/src/test/java/com/mallang/comment/query/CommentResponseValidatorTest.java index 09f5c31c..69eba28c 100644 --- a/src/test/java/com/mallang/comment/query/CommentResponseValidatorTest.java +++ b/src/test/java/com/mallang/comment/query/CommentResponseValidatorTest.java @@ -1,9 +1,9 @@ package com.mallang.comment.query; import static com.mallang.auth.MemberFixture.말랑; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.BDDMockito.given; @@ -14,7 +14,7 @@ import com.mallang.blog.domain.Blog; import com.mallang.post.domain.Post; import com.mallang.post.domain.PostRepository; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import com.mallang.post.exception.NoAuthorityAccessPostException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayNameGeneration; @@ -39,28 +39,25 @@ class CommentResponseValidatorTest { private final Post 공개_포스트 = Post.builder() .writer(owner) .visibilityPolish(new PostVisibilityPolicy(PUBLIC, null)) - .blog(blog) .build(); private final Post 보호_포스트 = Post.builder() .writer(owner) - .blog(blog) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) .build(); private final Post 비공개_포스트 = Post.builder() .writer(owner) - .blog(blog) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) .build(); @Test void 공개_포스트면_문제없다() { // given - given(postRepository.getById(1L)) + given(postRepository.getByIdAndBlogName(1L, blog.getName())) .willReturn(공개_포스트); // when & then assertDoesNotThrow(() -> { - commentDataValidator.validateAccessPost(1L, null, null); + commentDataValidator.validateAccessPost(1L, blog.getName(), null, null); }); } @@ -68,53 +65,53 @@ class CommentResponseValidatorTest { void 포스트_작성자와_조회자가_동일하면_보호든_비공개든_문제없다() { // given given(memberRepository.getById(10L)).willReturn(owner); - given(postRepository.getById(1L)) + given(postRepository.getByIdAndBlogName(1L, blog.getName())) .willReturn(비공개_포스트); - given(postRepository.getById(2L)) + given(postRepository.getByIdAndBlogName(2L, blog.getName())) .willReturn(보호_포스트); // when & then assertDoesNotThrow(() -> { - commentDataValidator.validateAccessPost(1L, owner.getId(), null); + commentDataValidator.validateAccessPost(1L, blog.getName(), owner.getId(), null); }); assertDoesNotThrow(() -> { - commentDataValidator.validateAccessPost(2L, owner.getId(), null); + commentDataValidator.validateAccessPost(2L, blog.getName(), owner.getId(), null); }); } @Test void 보호_포스트인_경우_비밀번호가_일치하면_문제없다() { // given - given(postRepository.getById(1L)) + given(postRepository.getByIdAndBlogName(1L, blog.getName())) .willReturn(보호_포스트); // when & then assertDoesNotThrow(() -> { - commentDataValidator.validateAccessPost(1L, null, "1234"); + commentDataValidator.validateAccessPost(1L, blog.getName(), null, "1234"); }); } @Test void 포스트_작성자가_아니며_보호_포스트인데_비밀번호가_다르면_예외() { // given - given(postRepository.getById(1L)) + given(postRepository.getByIdAndBlogName(1L, blog.getName())) .willReturn(보호_포스트); // when & then assertThatThrownBy(() -> { - commentDataValidator.validateAccessPost(1L, 999L, "12345"); + commentDataValidator.validateAccessPost(1L, blog.getName(), 999L, "12345"); }).isInstanceOf(NoAuthorityAccessPostException.class); } @Test void 포스트_작성자가_아닌데_비공개면_오류() { // given - given(postRepository.getById(1L)) + given(postRepository.getByIdAndBlogName(1L, blog.getName())) .willReturn(비공개_포스트); // when & then assertThatThrownBy(() -> { - commentDataValidator.validateAccessPost(1L, 999L, null); + commentDataValidator.validateAccessPost(1L, blog.getName(), 999L, null); }).isInstanceOf(NoAuthorityAccessPostException.class); } } diff --git a/src/test/java/com/mallang/common/ServiceTest.java b/src/test/java/com/mallang/common/ServiceTest.java index 829fee0f..1038bb60 100644 --- a/src/test/java/com/mallang/common/ServiceTest.java +++ b/src/test/java/com/mallang/common/ServiceTest.java @@ -1,7 +1,7 @@ package com.mallang.common; import static com.mallang.auth.domain.OauthServerType.GITHUB; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import com.mallang.auth.domain.Member; import com.mallang.auth.domain.MemberRepository; @@ -34,12 +34,13 @@ import com.mallang.post.application.command.DeletePostCommand; import com.mallang.post.application.command.UpdatePostCommand; import com.mallang.post.domain.Post; +import com.mallang.post.domain.PostId; import com.mallang.post.domain.PostOrderInBlogGenerator; import com.mallang.post.domain.PostRepository; +import com.mallang.post.domain.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.domain.like.PostLikeRepository; import com.mallang.post.domain.star.PostStarRepository; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; import com.mallang.post.query.PostQueryService; import com.mallang.post.query.PostStarQueryService; import com.mallang.post.query.dao.PostSearchDao; @@ -168,25 +169,25 @@ public abstract class ServiceTest { return name; } - protected Long 포스트를_저장한다(Long 회원_ID, String 블로그_이름, String 제목, String 내용, String... 태그들) { + protected PostId 포스트를_저장한다(Long 회원_ID, String 블로그_이름, String 제목, String 내용, String... 태그들) { return 포스트를_저장한다(회원_ID, 블로그_이름, 제목, 내용, PUBLIC, null, null, 태그들); } - protected Long 포스트를_저장한다(Long 회원_ID, String 블로그_이름, String 제목, String 내용, Long 카테고리_ID, String... 태그들) { + protected PostId 포스트를_저장한다(Long 회원_ID, String 블로그_이름, String 제목, String 내용, Long 카테고리_ID, String... 태그들) { return 포스트를_저장한다(회원_ID, 블로그_이름, 제목, 내용, PUBLIC, null, 카테고리_ID, 태그들); } - protected Long 포스트를_저장한다(Long 회원_ID, - String 블로그_이름, - String 제목, - String 내용, - PostVisibilityPolicy 공개범위, - String... 태그들 + protected PostId 포스트를_저장한다(Long 회원_ID, + String 블로그_이름, + String 제목, + String 내용, + PostVisibilityPolicy 공개범위, + String... 태그들 ) { return 포스트를_저장한다(회원_ID, 블로그_이름, 제목, 내용, 공개범위.getVisibility(), 공개범위.getPassword(), null, 태그들); } - protected Long 포스트를_저장한다( + protected PostId 포스트를_저장한다( Long 회원_ID, String 블로그_이름, String 제목, @@ -210,11 +211,12 @@ public abstract class ServiceTest { )); } - protected void 포스트_공개여부를_업데이트한다(Long 회원_ID, Long postId, Visibility visibility, String password) { - Post post = postRepository.getById(postId); + protected void 포스트_공개여부를_업데이트한다(Long 회원_ID, Long postId, String blogName, Visibility visibility, String password) { + Post post = postRepository.getByIdAndBlogName(postId, blogName); postService.update(new UpdatePostCommand( 회원_ID, postId, + blogName, post.getTitle(), post.getContent(), post.getPostThumbnailImageName(), @@ -226,13 +228,14 @@ public abstract class ServiceTest { )); } - protected void 포스트를_삭제한다(Long memberId, Long postId) { - postService.delete(new DeletePostCommand(memberId, List.of(postId))); + protected void 포스트를_삭제한다(Long memberId, Long postId, String blogName) { + postService.delete(new DeletePostCommand(memberId, List.of(postId), blogName)); } - public Long 댓글을_작성한다(Long postId, String content, boolean secret, Long memberId) { + public Long 댓글을_작성한다(Long postId, String blogName, String content, boolean secret, Long memberId) { WriteAuthCommentCommand command = WriteAuthCommentCommand.builder() .postId(postId) + .blogName(blogName) .content(content) .secret(secret) .memberId(memberId) @@ -240,9 +243,10 @@ public abstract class ServiceTest { return authCommentService.write(command); } - public Long 비인증_댓글을_작성한다(Long postId, String content, String nickname, String password) { + public Long 비인증_댓글을_작성한다(Long postId, String blogName, String content, String nickname, String password) { WriteUnAuthCommentCommand command = WriteUnAuthCommentCommand.builder() .postId(postId) + .blogName(blogName) .content(content) .nickname(nickname) .password(password) @@ -250,9 +254,17 @@ public abstract class ServiceTest { return unAuthCommentService.write(command); } - public Long 대댓글을_작성한다(Long postId, String content, boolean secret, Long memberId, Long parentCommentId) { + public Long 대댓글을_작성한다( + Long postId, + String blogName, + String content, + boolean secret, + Long memberId, + Long parentCommentId + ) { WriteAuthCommentCommand command = WriteAuthCommentCommand.builder() .postId(postId) + .blogName(blogName) .content(content) .secret(secret) .memberId(memberId) @@ -261,9 +273,17 @@ public abstract class ServiceTest { return authCommentService.write(command); } - public Long 비인증_대댓글을_작성한다(Long postId, String content, String nickname, String password, Long parentCommentId) { + public Long 비인증_대댓글을_작성한다( + Long postId, + String blogName, + String content, + String nickname, + String password, + Long parentCommentId + ) { WriteUnAuthCommentCommand command = WriteUnAuthCommentCommand.builder() .postId(postId) + .blogName(blogName) .content(content) .nickname(nickname) .password(password) diff --git a/src/test/java/com/mallang/post/application/PostEventHandlerTest.java b/src/test/java/com/mallang/post/application/PostEventHandlerTest.java index 5ac925ea..6d6891ac 100644 --- a/src/test/java/com/mallang/post/application/PostEventHandlerTest.java +++ b/src/test/java/com/mallang/post/application/PostEventHandlerTest.java @@ -28,17 +28,17 @@ class 카테고리_삭제_이벤트를_받아 { 말랑_ID, blogName, "최상위1", null)); Long categoryId2 = categoryService.create(new CreateCategoryCommand( 말랑_ID, blogName, "최상위2", null)); - Long postId1 = 포스트를_저장한다(말랑_ID, blogName, "제목1", "내용", categoryId1); - Long postId2 = 포스트를_저장한다(말랑_ID, blogName, "제목2", "내용", categoryId1); - Long postId3 = 포스트를_저장한다(말랑_ID, blogName, "안삭제", "내용", categoryId2); + Long postId1 = 포스트를_저장한다(말랑_ID, blogName, "제목1", "내용", categoryId1).getId(); + Long postId2 = 포스트를_저장한다(말랑_ID, blogName, "제목2", "내용", categoryId1).getId(); + Long postId3 = 포스트를_저장한다(말랑_ID, blogName, "안삭제", "내용", categoryId2).getId(); // when publisher.publishEvent(new CategoryDeletedEvent(categoryId1)); // then - assertThat(postRepository.getById((postId1)).getCategory()).isNull(); - assertThat(postRepository.getById((postId2)).getCategory()).isNull(); - assertThat(postRepository.getById((postId3)).getCategory()).isNotNull(); + assertThat(postRepository.getByIdAndBlogName(postId1, blogName).getCategory()).isNull(); + assertThat(postRepository.getByIdAndBlogName(postId2, blogName).getCategory()).isNull(); + assertThat(postRepository.getByIdAndBlogName(postId3, blogName).getCategory()).isNotNull(); } } } diff --git a/src/test/java/com/mallang/post/application/PostLikeEventHandlerTest.java b/src/test/java/com/mallang/post/application/PostLikeEventHandlerTest.java index 373ee75a..9df220d7 100644 --- a/src/test/java/com/mallang/post/application/PostLikeEventHandlerTest.java +++ b/src/test/java/com/mallang/post/application/PostLikeEventHandlerTest.java @@ -24,7 +24,7 @@ class PostLikeEventHandlerTest extends ServiceTest { void setUp() { memberId = 회원을_저장한다("말랑"); blogName = 블로그_개설(memberId, "mallang-log"); - postId = 포스트를_저장한다(memberId, blogName, "포스트", "내용", "태그1"); + postId = 포스트를_저장한다(memberId, blogName, "포스트", "내용", "태그1").getId(); } @Nested @@ -32,13 +32,13 @@ class 포스트_삭제_이벤트를_받아 { @Test void 해당_포스트에_눌린_좋아요를_모두_제거한다() { - postLikeService.like(new ClickPostLikeCommand(postId, memberId, null)); + postLikeService.like(new ClickPostLikeCommand(postId, blogName, memberId, null)); // when - 포스트를_삭제한다(memberId, postId); + 포스트를_삭제한다(memberId, postId, blogName); // then - assertThat(postLikeRepository.findByPostIdAndMemberId(postId, memberId)).isEmpty(); + assertThat(postLikeRepository.findByPostIdAndMemberId(postId, blogName, memberId)).isEmpty(); } } } diff --git a/src/test/java/com/mallang/post/application/PostLikeServiceTest.java b/src/test/java/com/mallang/post/application/PostLikeServiceTest.java index d0420026..f7b01823 100644 --- a/src/test/java/com/mallang/post/application/PostLikeServiceTest.java +++ b/src/test/java/com/mallang/post/application/PostLikeServiceTest.java @@ -1,8 +1,8 @@ package com.mallang.post.application; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -11,7 +11,7 @@ import com.mallang.post.application.command.CancelPostLikeCommand; import com.mallang.post.application.command.ClickPostLikeCommand; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import com.mallang.post.exception.AlreadyLikedPostException; import com.mallang.post.exception.NoAuthorityAccessPostException; import org.junit.jupiter.api.BeforeEach; @@ -44,19 +44,22 @@ void setUp() { blogName, "포스트", "내용", - new PostVisibilityPolicy(PUBLIC, null)); + new PostVisibilityPolicy(PUBLIC, null) + ).getId(); protectedPostId = 포스트를_저장한다( memberId, blogName, "포스트", "내용", - new PostVisibilityPolicy(PROTECTED, "1234")); + new PostVisibilityPolicy(PROTECTED, "1234") + ).getId(); privatePostId = 포스트를_저장한다( memberId, blogName, "포스트", "내용", - new PostVisibilityPolicy(PRIVATE, null)); + new PostVisibilityPolicy(PRIVATE, null) + ).getId(); } @Nested @@ -65,7 +68,7 @@ class 좋아요_시 { @Test void 로그인해야_좋아요를_누를_수_있다() { // given - ClickPostLikeCommand command = new ClickPostLikeCommand(publicPostId, null, null); + ClickPostLikeCommand command = new ClickPostLikeCommand(publicPostId, blogName, null, null); // when & then assertThatThrownBy(() -> { @@ -76,8 +79,8 @@ class 좋아요_시 { @Test void 회원이_이미_해당_포스트에_좋아요를_누른_경우_예외() { // given - postLikeService.like(new ClickPostLikeCommand(publicPostId, memberId, null)); - ClickPostLikeCommand command = new ClickPostLikeCommand(publicPostId, memberId, null); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, memberId, null)); + ClickPostLikeCommand command = new ClickPostLikeCommand(publicPostId, blogName, memberId, null); // when assertThatThrownBy(() -> { @@ -85,44 +88,44 @@ class 좋아요_시 { }).isInstanceOf(AlreadyLikedPostException.class); // then - Post post = postRepository.getById(publicPostId); + Post post = postRepository.getByIdAndBlogName(publicPostId, blogName); assertThat(post.getLikeCount()).isEqualTo(1); } @Test void 해당_포스트에_좋아요를_누른_적이_없으면_좋아요를_누른다() { // when - postLikeService.like(new ClickPostLikeCommand(publicPostId, memberId, null)); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, memberId, null)); // then - Post post = postRepository.getById(publicPostId); + Post post = postRepository.getByIdAndBlogName(publicPostId, blogName); assertThat(post.getLikeCount()).isEqualTo(1); } @Test void 글_작성자는_보호된_글에_좋아요를_누를_수_있다() { // when - postLikeService.like(new ClickPostLikeCommand(protectedPostId, memberId, null)); + postLikeService.like(new ClickPostLikeCommand(protectedPostId, blogName, memberId, null)); // then - Post post = postRepository.getById(protectedPostId); + Post post = postRepository.getByIdAndBlogName(protectedPostId, blogName); assertThat(post.getLikeCount()).isEqualTo(1); } @Test void 보호된_글의_비밀번호와_입력한_비밀번호가_일치하면_좋아요를_누를_수_있다() { // when - postLikeService.like(new ClickPostLikeCommand(protectedPostId, otherMemberId, "1234")); + postLikeService.like(new ClickPostLikeCommand(protectedPostId, blogName, otherMemberId, "1234")); // then - Post post = postRepository.getById(protectedPostId); + Post post = postRepository.getByIdAndBlogName(protectedPostId, blogName); assertThat(post.getLikeCount()).isEqualTo(1); } @Test void 보호된_글의_비밀번호와_입력한_비밀번호가_다르면_예외() { // given - ClickPostLikeCommand command = new ClickPostLikeCommand(protectedPostId, otherMemberId, "12345"); + ClickPostLikeCommand command = new ClickPostLikeCommand(protectedPostId, blogName, otherMemberId, "12345"); // when & then assertThatThrownBy(() -> { @@ -133,8 +136,8 @@ class 좋아요_시 { @Test void 비공개_글에는_작성자_말고는_좋아요를_누를_수_없다() { // given - ClickPostLikeCommand command1 = new ClickPostLikeCommand(privatePostId, memberId, null); - ClickPostLikeCommand command2 = new ClickPostLikeCommand(privatePostId, otherMemberId, null); + ClickPostLikeCommand command1 = new ClickPostLikeCommand(privatePostId, blogName, memberId, null); + ClickPostLikeCommand command2 = new ClickPostLikeCommand(privatePostId, blogName, otherMemberId, null); // when & then assertDoesNotThrow(() -> { @@ -152,69 +155,69 @@ class 좋아요_취소_시 { @Test void 좋아요_취소_시_좋아요가_제거된다() { // given - postLikeService.like(new ClickPostLikeCommand(publicPostId, memberId, null)); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, memberId, null)); // when - postLikeService.cancel(new CancelPostLikeCommand(publicPostId, memberId, null)); + postLikeService.cancel(new CancelPostLikeCommand(publicPostId, blogName, memberId, null)); // then - Post post = postRepository.getById(publicPostId); + Post post = postRepository.getByIdAndBlogName(publicPostId, blogName); assertThat(post.getLikeCount()).isZero(); } @Test void 글_작성자는_보호된_글에_누른_좋아요를_취소할_수_있다() { // given - postLikeService.like(new ClickPostLikeCommand(publicPostId, memberId, null)); - 포스트_공개여부를_업데이트한다(memberId, publicPostId, PROTECTED, "1234"); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, memberId, null)); + 포스트_공개여부를_업데이트한다(memberId, publicPostId, blogName, PROTECTED, "1234"); // when - postLikeService.cancel(new CancelPostLikeCommand(publicPostId, memberId, null)); + postLikeService.cancel(new CancelPostLikeCommand(publicPostId, blogName, memberId, null)); // then - Post post = postRepository.getById(publicPostId); + Post post = postRepository.getByIdAndBlogName(publicPostId, blogName); assertThat(post.getLikeCount()).isZero(); } @Test void 보호된_글의_비밀번호와_입력한_비밀번호가_일치하면_좋아요를_취소한_수_있다() { // given - postLikeService.like(new ClickPostLikeCommand(publicPostId, otherMemberId, null)); - 포스트_공개여부를_업데이트한다(memberId, publicPostId, PROTECTED, "1234"); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, otherMemberId, null)); + 포스트_공개여부를_업데이트한다(memberId, publicPostId, blogName, PROTECTED, "1234"); // when - postLikeService.cancel(new CancelPostLikeCommand(publicPostId, otherMemberId, "1234")); + postLikeService.cancel(new CancelPostLikeCommand(publicPostId, blogName, otherMemberId, "1234")); // then - Post post = postRepository.getById(publicPostId); + Post post = postRepository.getByIdAndBlogName(publicPostId, blogName); assertThat(post.getLikeCount()).isZero(); } @Test void 보호된_글의_비밀번호와_입력한_비밀번호가_다르면_예외() { // given - postLikeService.like(new ClickPostLikeCommand(publicPostId, otherMemberId, null)); - 포스트_공개여부를_업데이트한다(memberId, publicPostId, PROTECTED, "1234"); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, otherMemberId, null)); + 포스트_공개여부를_업데이트한다(memberId, publicPostId, blogName, PROTECTED, "1234"); // when & then assertThatThrownBy(() -> { - postLikeService.cancel(new CancelPostLikeCommand(publicPostId, otherMemberId, "12345")); + postLikeService.cancel(new CancelPostLikeCommand(publicPostId, blogName, otherMemberId, "12345")); }).isInstanceOf(NoAuthorityAccessPostException.class); } @Test void 비공개_글에는_작성자_말고는_좋아요를_취소할_수_없다() { // given - postLikeService.like(new ClickPostLikeCommand(publicPostId, memberId, null)); - postLikeService.like(new ClickPostLikeCommand(publicPostId, otherMemberId, null)); - 포스트_공개여부를_업데이트한다(memberId, publicPostId, PRIVATE, null); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, memberId, null)); + postLikeService.like(new ClickPostLikeCommand(publicPostId, blogName, otherMemberId, null)); + 포스트_공개여부를_업데이트한다(memberId, publicPostId, blogName, PRIVATE, null); // when & then assertDoesNotThrow(() -> { - postLikeService.cancel(new CancelPostLikeCommand(publicPostId, memberId, null)); + postLikeService.cancel(new CancelPostLikeCommand(publicPostId, blogName, memberId, null)); }); assertThatThrownBy(() -> { - postLikeService.cancel(new CancelPostLikeCommand(publicPostId, otherMemberId, null)); + postLikeService.cancel(new CancelPostLikeCommand(publicPostId, blogName, otherMemberId, null)); }).isInstanceOf(NoAuthorityAccessPostException.class); } } diff --git a/src/test/java/com/mallang/post/application/PostServiceTest.java b/src/test/java/com/mallang/post/application/PostServiceTest.java index 837521fc..f3696acc 100644 --- a/src/test/java/com/mallang/post/application/PostServiceTest.java +++ b/src/test/java/com/mallang/post/application/PostServiceTest.java @@ -1,6 +1,6 @@ package com.mallang.post.application; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -14,6 +14,7 @@ import com.mallang.post.application.command.UpdatePostCommand; import com.mallang.post.domain.Post; import com.mallang.post.domain.PostDeleteEvent; +import com.mallang.post.domain.PostId; import com.mallang.post.exception.NotFoundPostException; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -54,7 +55,7 @@ void setUp() { .build(); // when - Long id = postService.create(command); + Long id = postService.create(command).getId(); // then assertThat(id).isNotNull(); @@ -77,11 +78,11 @@ void setUp() { .build(); // when - Long id = postService.create(command); + Long id = postService.create(command).getId(); // then transactionHelper.doAssert(() -> { - Post post = postRepository.getById(id); + Post post = postRepository.getByIdAndBlogName(id, blogName); assertThat(post.getCategory().getName()).isEqualTo("Spring"); }); } @@ -119,11 +120,11 @@ void setUp() { .build(); // when - Long id = postService.create(command); + Long id = postService.create(command).getId(); // then transactionHelper.doAssert(() -> { - Post post = postRepository.getById(id); + Post post = postRepository.getByIdAndBlogName(id, blogName); assertThat(post.getTags()) .containsExactly("tag1", "tag2", "tag3"); }); @@ -142,10 +143,11 @@ void setUp() { @Test void 내가_쓴_포스트를_수정할_수_있다() { // given - Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용", "태그1"); + Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용", "태그1").getId(); // when - postService.update(new UpdatePostCommand(memberId, 포스트_ID, + postService.update(new UpdatePostCommand( + memberId, 포스트_ID, blogName, "수정제목", "수정내용", "수정썸네일", "수정인트로", @@ -154,7 +156,7 @@ void setUp() { // then transactionHelper.doAssert(() -> { - Post post = postRepository.getById(포스트_ID); + Post post = postRepository.getByIdAndBlogName(포스트_ID, blogName); assertThat(post.getTitle()).isEqualTo("수정제목"); assertThat(post.getContent()).isEqualTo("수정내용"); assertThat(post.getPostThumbnailImageName()).isEqualTo("수정썸네일"); @@ -168,12 +170,13 @@ void setUp() { void 다른_사람의_포스트는_수정할_수_없다() { // given Long otherMemberId = 회원을_저장한다("동훈"); - Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용"); + Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용").getId(); // when assertThatThrownBy(() -> postService.update( - new UpdatePostCommand(otherMemberId, 포스트_ID, + new UpdatePostCommand( + otherMemberId, 포스트_ID, blogName, "수정제목", "수정내용", null, "수정인트로", PUBLIC, null, @@ -181,7 +184,7 @@ null, emptyList())) ).isInstanceOf(NotFoundPostException.class); // then - Post post = postRepository.getById(포스트_ID); + Post post = postRepository.getByIdAndBlogName(포스트_ID, blogName); assertThat(post.getTitle()).isEqualTo("포스트"); assertThat(post.getContent()).isEqualTo("내용"); } @@ -192,17 +195,18 @@ null, emptyList())) Long springCategoryId = categoryService.create(new CreateCategoryCommand( memberId, blogName, "Spring", null )); - Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용", springCategoryId); + Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용", springCategoryId).getId(); // when - postService.update(new UpdatePostCommand(memberId, 포스트_ID, + postService.update(new UpdatePostCommand( + memberId, 포스트_ID, blogName, "수정제목", "수정내용", null, "수정인트로", PUBLIC, null, null, emptyList())); // then - Post post = postRepository.getById(포스트_ID); + Post post = postRepository.getByIdAndBlogName(포스트_ID, blogName); assertThat(post.getTitle()).isEqualTo("수정제목"); assertThat(post.getContent()).isEqualTo("수정내용"); assertThat(post.getCategory()).isNull(); @@ -211,14 +215,15 @@ null, emptyList())) @Test void 포스트_수정_시_없던_카테고리를_설정할_수_있다() { // given - Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용"); + Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용").getId(); Long springCategoryId = categoryService.create(new CreateCategoryCommand( memberId, blogName, "Spring", null )); // when postService.update( - new UpdatePostCommand(memberId, 포스트_ID, + new UpdatePostCommand( + memberId, 포스트_ID, blogName, "수정제목", "수정내용", null, "수정인트로", PUBLIC, null, @@ -226,7 +231,7 @@ null, emptyList())) // then transactionHelper.doAssert(() -> { - Post post = postRepository.getById(포스트_ID); + Post post = postRepository.getByIdAndBlogName(포스트_ID, blogName); assertThat(post.getTitle()).isEqualTo("수정제목"); assertThat(post.getContent()).isEqualTo("수정내용"); assertThat(post.getCategory().getName()).isEqualTo("Spring"); @@ -239,13 +244,12 @@ null, emptyList())) Long springCategoryId = categoryService.create(new CreateCategoryCommand( memberId, blogName, "Spring", null )); - Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용", springCategoryId); + Long 포스트_ID = 포스트를_저장한다(memberId, blogName, "포스트", "내용", springCategoryId).getId(); Long nodeCategoryId = categoryService.create(new CreateCategoryCommand(memberId, blogName, "Node", null)); // when postService.update(new UpdatePostCommand( - memberId, - 포스트_ID, + memberId, 포스트_ID, blogName, "수정제목", "수정내용", null, "수정인트로", PUBLIC, null, @@ -253,7 +257,7 @@ null, emptyList())) // then transactionHelper.doAssert(() -> { - Post post = postRepository.getById(포스트_ID); + Post post = postRepository.getByIdAndBlogName(포스트_ID, blogName); assertThat(post.getTitle()).isEqualTo("수정제목"); assertThat(post.getContent()).isEqualTo("수정내용"); assertThat(post.getCategory().getName()).isEqualTo("Node"); @@ -264,10 +268,11 @@ null, emptyList())) @Nested class 포스트_제거_시 { - private Long myPostId1; - private Long myPostId2; + private PostId myPostId1; + private PostId myPostId2; private Long otherId; - private Long otherPostId; + private String otherBlogName; + private PostId otherPostId; @BeforeEach void setUp() { @@ -275,41 +280,42 @@ void setUp() { blogName = 블로그_개설(memberId, "mallang-log"); myPostId1 = 포스트를_저장한다(memberId, blogName, "내 글 1", "내 글 1 입니다."); myPostId2 = 포스트를_저장한다(memberId, blogName, "내 글 2", "내 글 2 입니다."); - 댓글을_작성한다(myPostId1, "dw", false, memberId); + 댓글을_작성한다(myPostId1.getId(), blogName, "dw", false, memberId); otherId = 회원을_저장한다("other"); - String otherBlogName = 블로그_개설(otherId, "other-log"); + otherBlogName = 블로그_개설(otherId, "other-log"); otherPostId = 포스트를_저장한다(otherId, otherBlogName, "다른사람 글 1", "다른사람 글 1 입니다."); } @Test void 자신이_작성한_글이_아닌_경우_아무것도_지워지지_않는다() { // when - postService.delete(new DeletePostCommand(otherId, List.of(myPostId1))); + postService.delete(new DeletePostCommand(otherId, List.of(myPostId1.getId()), blogName)); // then - assertThat(postRepository.existsById(myPostId1)).isTrue(); + assertThat(postRepository.findByIdAndBlogName(myPostId1.getId(), blogName)).isPresent(); assertThat(EventsTestUtils.count(events, PostDeleteEvent.class)).isZero(); } @Test void 없는_글이_있으면_제외하고_제거된다() { // when - postService.delete(new DeletePostCommand(memberId, List.of(myPostId1, 100000L))); + postService.delete(new DeletePostCommand(memberId, List.of(myPostId1.getId(), 100000L), blogName)); // then - assertThat(postRepository.existsById(myPostId1)).isFalse(); + assertThat(postRepository.findByIdAndBlogName(myPostId1.getId(), blogName)).isEmpty(); assertThat(EventsTestUtils.count(events, PostDeleteEvent.class)).isEqualTo(1); } @Test void 원하는_포스트들을_제거하며_각각_댓글_제거_이벤트가_발행된다() { // when - postService.delete(new DeletePostCommand(memberId, List.of(myPostId1, myPostId2))); + postService.delete( + new DeletePostCommand(memberId, List.of(myPostId1.getId(), myPostId2.getId()), blogName)); // then - assertThat(postRepository.existsById(myPostId1)).isFalse(); - assertThat(postRepository.existsById(myPostId2)).isFalse(); - assertThat(postRepository.existsById(otherPostId)).isTrue(); + assertThat(postRepository.findByIdAndBlogName(myPostId1.getId(), blogName)).isEmpty(); + assertThat(postRepository.findByIdAndBlogName(myPostId2.getId(), blogName)).isEmpty(); + assertThat(postRepository.findByIdAndBlogName(otherPostId.getId(), otherBlogName)).isPresent(); assertThat(EventsTestUtils.count(events, PostDeleteEvent.class)).isEqualTo(2); } } diff --git a/src/test/java/com/mallang/post/application/PostStarEventHandlerTest.java b/src/test/java/com/mallang/post/application/PostStarEventHandlerTest.java index 8d81e6a8..3324a2a0 100644 --- a/src/test/java/com/mallang/post/application/PostStarEventHandlerTest.java +++ b/src/test/java/com/mallang/post/application/PostStarEventHandlerTest.java @@ -24,7 +24,7 @@ class PostStarEventHandlerTest extends ServiceTest { void setUp() { memberId = 회원을_저장한다("말랑"); blogName = 블로그_개설(memberId, "mallang-log"); - postId = 포스트를_저장한다(memberId, blogName, "포스트", "내용", "태그1"); + postId = 포스트를_저장한다(memberId, blogName, "포스트", "내용", "태그1").getId(); } @Nested @@ -32,13 +32,13 @@ class 포스트_삭제_이벤트를_받아 { @Test void 해당_포스트에_눌린_좋아요를_모두_제거한다() { - postStarService.star(new StarPostCommand(postId, memberId, null)); + postStarService.star(new StarPostCommand(postId, blogName, memberId, null)); // when - 포스트를_삭제한다(memberId, postId); + 포스트를_삭제한다(memberId, postId, blogName); // then - assertThat(postStarRepository.findByPostIdAndMemberId(postId, memberId)).isEmpty(); + assertThat(postStarRepository.findByPostIdAndBlogNameAndMemberId(postId, blogName, memberId)).isEmpty(); } } } diff --git a/src/test/java/com/mallang/post/application/PostStarServiceTest.java b/src/test/java/com/mallang/post/application/PostStarServiceTest.java index c71393f9..1b2fb2ef 100644 --- a/src/test/java/com/mallang/post/application/PostStarServiceTest.java +++ b/src/test/java/com/mallang/post/application/PostStarServiceTest.java @@ -1,8 +1,8 @@ package com.mallang.post.application; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -11,7 +11,7 @@ import com.mallang.post.application.command.CancelPostStarCommand; import com.mallang.post.application.command.StarPostCommand; import com.mallang.post.domain.Post; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import com.mallang.post.exception.AlreadyStarPostException; import com.mallang.post.exception.NoAuthorityAccessPostException; import org.junit.jupiter.api.BeforeEach; @@ -44,19 +44,22 @@ void setUp() { blogName, "포스트", "내용", - new PostVisibilityPolicy(PUBLIC, null)); + new PostVisibilityPolicy(PUBLIC, null) + ).getId(); protectedPostId = 포스트를_저장한다( memberId, blogName, "포스트", "내용", - new PostVisibilityPolicy(PROTECTED, "1234")); + new PostVisibilityPolicy(PROTECTED, "1234") + ).getId(); privatePostId = 포스트를_저장한다( memberId, blogName, "포스트", "내용", - new PostVisibilityPolicy(PRIVATE, null)); + new PostVisibilityPolicy(PRIVATE, null) + ).getId(); } @Nested @@ -65,7 +68,7 @@ class 즐겨찾기_시 { @Test void 로그인해야_즐겨찾기를_누를_수_있다() { // given - StarPostCommand command = new StarPostCommand(publicPostId, null, null); + StarPostCommand command = new StarPostCommand(publicPostId, blogName, null, null); // when & then assertThatThrownBy(() -> { @@ -76,8 +79,8 @@ class 즐겨찾기_시 { @Test void 회원이_이미_해당_포스트에_즐겨찾기를_누른_경우_예외() { // given - postStarService.star(new StarPostCommand(publicPostId, memberId, null)); - StarPostCommand command = new StarPostCommand(publicPostId, memberId, null); + postStarService.star(new StarPostCommand(publicPostId, blogName, memberId, null)); + StarPostCommand command = new StarPostCommand(publicPostId, blogName, memberId, null); // when & then assertThatThrownBy(() -> { @@ -88,7 +91,7 @@ class 즐겨찾기_시 { @Test void 해당_포스트에_즐겨찾기를_누른_적이_없으면_즐겨찾기를_누른다() { // when - Long starId = postStarService.star(new StarPostCommand(publicPostId, memberId, null)); + Long starId = postStarService.star(new StarPostCommand(publicPostId, blogName, memberId, null)); // then assertThat(starId).isNotNull(); @@ -97,7 +100,7 @@ class 즐겨찾기_시 { @Test void 글_작성자는_보호된_글에_즐겨찾기를_누를_수_있다() { // when - Long starId = postStarService.star(new StarPostCommand(protectedPostId, memberId, null)); + Long starId = postStarService.star(new StarPostCommand(protectedPostId, blogName, memberId, null)); // then assertThat(starId).isNotNull(); @@ -106,7 +109,7 @@ class 즐겨찾기_시 { @Test void 보호된_글의_비밀번호와_입력한_비밀번호가_일치하면_즐겨찾기를_누를_수_있다() { // when - Long starId = postStarService.star(new StarPostCommand(protectedPostId, otherMemberId, "1234")); + Long starId = postStarService.star(new StarPostCommand(protectedPostId, blogName, otherMemberId, "1234")); // then assertThat(starId).isNotNull(); @@ -115,7 +118,7 @@ class 즐겨찾기_시 { @Test void 보호된_글의_비밀번호와_입력한_비밀번호가_다르면_예외() { // given - StarPostCommand command = new StarPostCommand(protectedPostId, otherMemberId, "12345"); + StarPostCommand command = new StarPostCommand(protectedPostId, blogName, otherMemberId, "12345"); // when & then assertThatThrownBy(() -> { @@ -126,8 +129,8 @@ class 즐겨찾기_시 { @Test void 비공개_글에는_작성자_말고는_즐겨찾기를_누를_수_없다() { // given - StarPostCommand command1 = new StarPostCommand(privatePostId, memberId, null); - StarPostCommand command2 = new StarPostCommand(privatePostId, otherMemberId, null); + StarPostCommand command1 = new StarPostCommand(privatePostId, blogName, memberId, null); + StarPostCommand command2 = new StarPostCommand(privatePostId, blogName, otherMemberId, null); // when & then assertDoesNotThrow(() -> { @@ -145,29 +148,29 @@ class 즐겨찾기_취소_시 { @Test void 즐겨찾기_취소_시_즐겨찾기가_제거된다() { // given - postStarService.star(new StarPostCommand(publicPostId, memberId, null)); + postStarService.star(new StarPostCommand(publicPostId, blogName, memberId, null)); // when - postStarService.cancel(new CancelPostStarCommand(publicPostId, memberId)); + postStarService.cancel(new CancelPostStarCommand(memberId, publicPostId, blogName)); // then - Post post = postRepository.getById(publicPostId); + Post post = postRepository.getByIdAndBlogName(publicPostId, blogName); assertThat(post.getLikeCount()).isZero(); } @Test void 보호글_비공개글_여부에_관계없이_취소할_수_있다() { // given - postStarService.star(new StarPostCommand(protectedPostId, otherMemberId, "1234")); - postStarService.star(new StarPostCommand(publicPostId, otherMemberId, null)); - 포스트_공개여부를_업데이트한다(memberId, publicPostId, PRIVATE, null); + postStarService.star(new StarPostCommand(protectedPostId, blogName, otherMemberId, "1234")); + postStarService.star(new StarPostCommand(publicPostId, blogName, otherMemberId, null)); + 포스트_공개여부를_업데이트한다(memberId, publicPostId, blogName, PRIVATE, null); // when & then assertDoesNotThrow(() -> { - postStarService.cancel(new CancelPostStarCommand(protectedPostId, otherMemberId)); + postStarService.cancel(new CancelPostStarCommand(otherMemberId, protectedPostId, blogName)); }); assertDoesNotThrow(() -> { - postStarService.cancel(new CancelPostStarCommand(publicPostId, otherMemberId)); + postStarService.cancel(new CancelPostStarCommand(otherMemberId, publicPostId, blogName)); }); } } diff --git a/src/test/java/com/mallang/post/domain/PostIdTest.java b/src/test/java/com/mallang/post/domain/PostIdTest.java new file mode 100644 index 00000000..39c62bac --- /dev/null +++ b/src/test/java/com/mallang/post/domain/PostIdTest.java @@ -0,0 +1,31 @@ +package com.mallang.post.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.Test; + +@DisplayName("포스트 ID(PostId) 은(는)") +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(ReplaceUnderscores.class) +class PostIdTest { + + @Test + void id와_blogId가_동일하면_같다() { + // given + PostId postId = new PostId(1L, 2L); + PostId same = new PostId(1L, 2L); + PostId other1 = new PostId(2L, 2L); + PostId other2 = new PostId(1L, 1L); + + // when & then + assertThat(postId) + .hasSameHashCodeAs(same) + .isEqualTo(same) + .isNotEqualTo(new Object()) + .isNotEqualTo(other1) + .isNotEqualTo(other2); + } +} diff --git a/src/test/java/com/mallang/post/domain/PostOrderInBlogGeneratorTest.java b/src/test/java/com/mallang/post/domain/PostOrderInBlogGeneratorTest.java index c8e778ca..5c939047 100644 --- a/src/test/java/com/mallang/post/domain/PostOrderInBlogGeneratorTest.java +++ b/src/test/java/com/mallang/post/domain/PostOrderInBlogGeneratorTest.java @@ -27,8 +27,11 @@ class PostOrderInBlogGeneratorTest extends ServiceTest { 포스트를_저장한다(otherId, otherBlogName, "글1", "1"); // when & then - assertThat(postOrderInBlogGenerator.generate(blogRepository.getByName(blogName))).isEqualTo(3); - assertThat(postOrderInBlogGenerator.generate(blogRepository.getByName(otherBlogName))).isEqualTo(2); - assertThat(postOrderInBlogGenerator.generate(blogRepository.getByName(thirdBlogName))).isEqualTo(1); + PostId postId = postOrderInBlogGenerator.generate(blogRepository.getByName(blogName).getId()); + PostId ohterPostId = postOrderInBlogGenerator.generate(blogRepository.getByName(otherBlogName).getId()); + PostId thirdPostId = postOrderInBlogGenerator.generate(blogRepository.getByName(thirdBlogName).getId()); + assertThat(postId.getId()).isEqualTo(3); + assertThat(ohterPostId.getId()).isEqualTo(2); + assertThat(thirdPostId.getId()).isEqualTo(1); } } diff --git a/src/test/java/com/mallang/post/domain/PostTest.java b/src/test/java/com/mallang/post/domain/PostTest.java index 86c07bca..95657ded 100644 --- a/src/test/java/com/mallang/post/domain/PostTest.java +++ b/src/test/java/com/mallang/post/domain/PostTest.java @@ -4,9 +4,9 @@ import static com.mallang.auth.MemberFixture.말랑; import static com.mallang.category.CategoryFixture.루트_카테고리; import static com.mallang.category.CategoryFixture.하위_카테고리; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; @@ -14,8 +14,7 @@ import com.mallang.auth.domain.Member; import com.mallang.blog.domain.Blog; import com.mallang.category.domain.Category; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.exception.DuplicatedTagsInPostException; import com.mallang.post.exception.NoAuthorityAccessPostException; import com.mallang.post.exception.PostLikeCountNegativeException; @@ -25,6 +24,7 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.springframework.test.util.ReflectionTestUtils; @DisplayName("포스트(Post) 은(는)") @SuppressWarnings("NonAsciiCharacters") @@ -39,6 +39,22 @@ class PostTest { private final Category jpaCategory = 하위_카테고리("JPA", mallang, blog, springCategory); private final Category otherMemberCategory = 루트_카테고리("otherMemberCategory", otherMember, otherBlog); + @Test + void Id가_같으면_동일하다() { + // given + Post post1 = Post.builder().title("1").build(); + Post post2 = Post.builder().title("2").build(); + ReflectionTestUtils.setField(post1, "postId", new PostId(1L, 2L)); + ReflectionTestUtils.setField(post2, "postId", new PostId(1L, 2L)); + + // when & then + assertThat(post1) + .isEqualTo(post1) + .hasSameHashCodeAs(post2) + .isEqualTo(post2) + .isNotEqualTo(new Object()); + } + @Test void 카테고리를_없앨_수_있다() { // given @@ -46,7 +62,6 @@ class PostTest { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .category(springCategory) .build(); @@ -67,7 +82,6 @@ class 생성_시 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .tags(List.of("tag1", "tag2")) .build(); @@ -83,7 +97,6 @@ class 생성_시 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); // when & then @@ -98,7 +111,6 @@ class 생성_시 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .tags(List.of("태그1", "태그1")) .build() ).isInstanceOf(DuplicatedTagsInPostException.class); @@ -111,7 +123,6 @@ class 생성_시 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .category(jpaCategory) .build(); @@ -127,7 +138,6 @@ class 생성_시 { .content("내용") .postThumbnailImageName("thumbnail") .writer(mallang) - .blog(blog) .build(); // when & then @@ -141,7 +151,6 @@ class 생성_시 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); // when & then @@ -159,7 +168,6 @@ class 수정_시 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .visibilityPolish(new PostVisibilityPolicy(Visibility.PROTECTED, "123")) .tags(List.of("태그1")) .build(); @@ -187,7 +195,6 @@ class 삭제_시 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); @Test @@ -222,7 +229,6 @@ class 공개_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PUBLIC, null)) - .blog(blog) .category(springCategory) .build(); @@ -247,7 +253,6 @@ class 보호_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .category(springCategory) .build(); @@ -284,7 +289,6 @@ class 비공개_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .category(springCategory) .build(); @@ -313,7 +317,6 @@ class 비공개_포스트인_경우 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); // when @@ -329,7 +332,6 @@ class 비공개_포스트인_경우 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); post.clickLike(); post.clickLike(); @@ -349,7 +351,6 @@ class 비공개_포스트인_경우 { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); // when diff --git a/src/test/java/com/mallang/post/domain/like/PostLikeTest.java b/src/test/java/com/mallang/post/domain/like/PostLikeTest.java index 09e99b82..4abd3cc8 100644 --- a/src/test/java/com/mallang/post/domain/like/PostLikeTest.java +++ b/src/test/java/com/mallang/post/domain/like/PostLikeTest.java @@ -2,9 +2,9 @@ import static com.mallang.auth.MemberFixture.말랑; import static com.mallang.auth.MemberFixture.회원; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -16,7 +16,7 @@ import com.mallang.blog.domain.Blog; import com.mallang.post.domain.Post; import com.mallang.post.domain.PostIntro; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import com.mallang.post.exception.AlreadyLikedPostException; import com.mallang.post.exception.NoAuthorityAccessPostException; import org.junit.jupiter.api.DisplayName; @@ -39,7 +39,6 @@ class PostLikeTest { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PUBLIC, null)) - .blog(blog) .build(); @Nested @@ -98,7 +97,6 @@ class 보호_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -146,7 +144,6 @@ class 비공개_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); @Test @@ -216,7 +213,6 @@ class 보호_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PROTECTED, "1234")) - .blog(blog) .build(); @Test @@ -270,7 +266,6 @@ class 비공개_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PRIVATE, null)) - .blog(blog) .build(); PostLike postLike = new PostLike(post, mallang); postLike.like(postLikeValidator, null); @@ -290,7 +285,6 @@ class 비공개_포스트인_경우 { .content("내용") .writer(mallang) .visibilityPolish(new PostVisibilityPolicy(PUBLIC, null)) - .blog(blog) .build(); PostLike postLike = new PostLike(post, other); postLike.like(postLikeValidator, null); diff --git a/src/test/java/com/mallang/post/domain/like/PostLikeValidatorTest.java b/src/test/java/com/mallang/post/domain/like/PostLikeValidatorTest.java index eed2c174..d1f63d1b 100644 --- a/src/test/java/com/mallang/post/domain/like/PostLikeValidatorTest.java +++ b/src/test/java/com/mallang/post/domain/like/PostLikeValidatorTest.java @@ -28,7 +28,6 @@ class PostLikeValidatorTest { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); @Test diff --git a/src/test/java/com/mallang/post/domain/star/PostStarValidatorTest.java b/src/test/java/com/mallang/post/domain/star/PostStarValidatorTest.java index fbcb65d4..f220b53c 100644 --- a/src/test/java/com/mallang/post/domain/star/PostStarValidatorTest.java +++ b/src/test/java/com/mallang/post/domain/star/PostStarValidatorTest.java @@ -28,7 +28,6 @@ class PostStarValidatorTest { .title("제목") .content("내용") .writer(mallang) - .blog(blog) .build(); @Test diff --git a/src/test/java/com/mallang/post/domain/visibility/PostVisibilityPolicyTest.java b/src/test/java/com/mallang/post/domain/visibility/PostVisibilityPolicyTest.java index cad964d1..70e7941c 100644 --- a/src/test/java/com/mallang/post/domain/visibility/PostVisibilityPolicyTest.java +++ b/src/test/java/com/mallang/post/domain/visibility/PostVisibilityPolicyTest.java @@ -3,7 +3,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.exception.ProtectVisibilityPasswordMustRequired; import com.mallang.post.exception.VisibilityPasswordNotRequired; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/mallang/post/query/PostDataProtectorTest.java b/src/test/java/com/mallang/post/query/PostDataProtectorTest.java index dab3cc22..f004fdef 100644 --- a/src/test/java/com/mallang/post/query/PostDataProtectorTest.java +++ b/src/test/java/com/mallang/post/query/PostDataProtectorTest.java @@ -1,11 +1,11 @@ package com.mallang.post.query; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.query.response.PostDetailResponse; import com.mallang.post.query.response.PostSearchResponse; import com.mallang.post.query.response.PostSearchResponse.WriterResponse; diff --git a/src/test/java/com/mallang/post/query/PostDataValidatorTest.java b/src/test/java/com/mallang/post/query/PostDataValidatorTest.java index 27e73d33..33159f8a 100644 --- a/src/test/java/com/mallang/post/query/PostDataValidatorTest.java +++ b/src/test/java/com/mallang/post/query/PostDataValidatorTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility; +import com.mallang.post.domain.PostVisibilityPolicy.Visibility; import com.mallang.post.query.response.PostDetailResponse; import com.mallang.post.query.response.PostDetailResponse.WriterResponse; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/mallang/post/query/PostQueryServiceTest.java b/src/test/java/com/mallang/post/query/PostQueryServiceTest.java index bc8fbeb1..5cfbf3ce 100644 --- a/src/test/java/com/mallang/post/query/PostQueryServiceTest.java +++ b/src/test/java/com/mallang/post/query/PostQueryServiceTest.java @@ -1,8 +1,8 @@ package com.mallang.post.query; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -130,10 +130,10 @@ class 포스트_단일_조회_시 { @Test void 포스트를_조회한다() { // given - Long id = postService.create(말랑_public_포스트_작성_요청); + Long id = postService.create(말랑_public_포스트_작성_요청).getId(); // when - PostDetailResponse response = postQueryService.getById(null, null, id); + PostDetailResponse response = postQueryService.getByIdAndBlogName(id, mallangBlogName, null, null); // then assertThat(response) @@ -152,12 +152,13 @@ class 포스트_단일_조회_시 { @Test void 좋아요_눌렀는지_여부가_반영된다() { // given - Long id = postService.create(말랑_public_포스트_작성_요청); - postLikeService.like(new ClickPostLikeCommand(id, mallangId, null)); + Long id = postService.create(말랑_public_포스트_작성_요청).getId(); + postLikeService.like(new ClickPostLikeCommand(id, mallangBlogName, mallangId, null)); // when - PostDetailResponse responseClickLike = postQueryService.getById(mallangId, null, id); - PostDetailResponse responseNoLike = postQueryService.getById(null, null, id); + PostDetailResponse responseClickLike = postQueryService.getByIdAndBlogName(id, mallangBlogName, mallangId, + null); + PostDetailResponse responseNoLike = postQueryService.getByIdAndBlogName(id, mallangBlogName, null, null); // then assertThat(responseClickLike.isLiked()).isTrue(); @@ -167,10 +168,10 @@ class 포스트_단일_조회_시 { @Test void 블로그_주인은_비공개_글을_볼_수_있다() { // given - Long id = postService.create(말랑_private_포스트_작성_요청); + Long id = postService.create(말랑_private_포스트_작성_요청).getId(); // when - PostDetailResponse response = postQueryService.getById(mallangId, null, id); + PostDetailResponse response = postQueryService.getByIdAndBlogName(id, mallangBlogName, mallangId, null); // then assertThat(response.id()).isEqualTo(id); @@ -179,21 +180,21 @@ class 포스트_단일_조회_시 { @Test void 블로그_주인이_아니라면_비공개_글_조회시_예외() { // given - Long id = postService.create(말랑_private_포스트_작성_요청); + Long id = postService.create(말랑_private_포스트_작성_요청).getId(); // when & then assertThatThrownBy(() -> - postQueryService.getById(mallangId + 1, null, id) + postQueryService.getByIdAndBlogName(id, mallangBlogName, mallangId + 1, null) ).isInstanceOf(NoAuthorityAccessPostException.class); } @Test void 블로그_주인은_보호글을_볼_수_있다() { // given - Long id = postService.create(말랑_protected_포스트_작성_요청); + Long id = postService.create(말랑_protected_포스트_작성_요청).getId(); // when - PostDetailResponse response = postQueryService.getById(mallangId, null, id); + PostDetailResponse response = postQueryService.getByIdAndBlogName(id, mallangBlogName, mallangId, null); // then assertThat(response.id()).isEqualTo(id); @@ -204,10 +205,11 @@ class 포스트_단일_조회_시 { @Test void 블로그_주인이_아닌_경우_비밀번호가_일치하면_보호글을_볼_수_있다() { // given - Long id = postService.create(말랑_protected_포스트_작성_요청); + Long id = postService.create(말랑_protected_포스트_작성_요청).getId(); // when - PostDetailResponse response = postQueryService.getById(mallangId + 1, "1234", id); + PostDetailResponse response = postQueryService.getByIdAndBlogName(id, mallangBlogName, mallangId + 1, + "1234"); // then assertThat(response.id()).isEqualTo(id); @@ -218,10 +220,10 @@ class 포스트_단일_조회_시 { @Test void 블로그_주인이_아니며_비밀번호가_일치하지_않는_경우_보호글_조회시_내용이_보호된다() { // given - Long id = postService.create(말랑_protected_포스트_작성_요청); + Long id = postService.create(말랑_protected_포스트_작성_요청).getId(); // when - PostDetailResponse response = postQueryService.getById(mallangId + 1, null, id); + PostDetailResponse response = postQueryService.getByIdAndBlogName(id, mallangBlogName, mallangId + 1, null); // then assertThat(response) @@ -245,12 +247,12 @@ class 포스트_검색_시 { @Test void 포스트를_전체_조회한다() { // given - Long post1Id = postService.create(말랑_public_포스트_작성_요청); - Long post2Id = postService.create(말랑_public_포스트_작성_요청); + Long post1Id = postService.create(말랑_public_포스트_작성_요청).getId(); + Long post2Id = postService.create(말랑_public_포스트_작성_요청).getId(); PostSearchCond cond = PostSearchCond.builder().build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -270,9 +272,9 @@ class 포스트_검색_시 { postService.create(동훈_private_포스트_작성_요청); // when - List search = postQueryService.search(mallangId, - new PostSearchCond(null, null, null, null, - null, null, null), pageable) + List search = postQueryService.search(new PostSearchCond(null, null, null, null, + null, null, null), pageable, mallangId + ) .getContent(); // then @@ -291,7 +293,7 @@ class 포스트_검색_시 { // given Long 스프링 = categoryService.create(new CreateCategoryCommand(mallangId, mallangBlogName, "스프링", null)); Long 노드 = categoryService.create(new CreateCategoryCommand(mallangId, mallangBlogName, "노드", null)); - Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "content1", 스프링); + Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "content1", 스프링).getId(); 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "content2", 노드); PostSearchCond cond = PostSearchCond.builder() .categoryId(스프링) @@ -299,7 +301,7 @@ class 포스트_검색_시 { .build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -322,15 +324,15 @@ class 포스트_검색_시 { // given Long 스프링 = categoryService.create(new CreateCategoryCommand(mallangId, mallangBlogName, "스프링", null)); Long JPA = categoryService.create(new CreateCategoryCommand(mallangId, mallangBlogName, "JPA", 스프링)); - Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "content1", 스프링); - Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "content2", JPA); + Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "content1", 스프링).getId(); + Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "content2", JPA).getId(); PostSearchCond cond = PostSearchCond.builder() .categoryId(스프링) .blogName(mallangBlogName) .build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -358,15 +360,15 @@ class 포스트_검색_시 { @Test void 특정_태그의_포스트만_조회한다() { // given - Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "content1", "tag1"); - Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "content2", "tag1", - "tag2"); + Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "content1", "tag1").getId(); + Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "content2", "tag1", "tag2") + .getId(); PostSearchCond cond = PostSearchCond.builder() .tag("tag2") .build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -389,15 +391,15 @@ class 포스트_검색_시 { // given Long findWriterId = 회원을_저장한다("말랑말랑"); String otherBlogName = 블로그_개설(findWriterId, "other"); - Long post1Id = 포스트를_저장한다(findWriterId, otherBlogName, "포스트1", "content1", "tag1"); - Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "content2", "tag1", - "tag2"); + Long post1Id = 포스트를_저장한다(findWriterId, otherBlogName, "포스트1", "content1", "tag1").getId(); + Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "content2", "tag1", "tag2") + .getId(); PostSearchCond cond = PostSearchCond.builder() .writerId(findWriterId) .build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -418,15 +420,15 @@ class 포스트_검색_시 { @Test void 제목으로_조회() { // given - Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "안녕"); - Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "안녕하세요"); - Long post3Id = 포스트를_저장한다(mallangId, mallangBlogName, "안녕", "히히"); + Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "안녕").getId(); + Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "안녕하세요").getId(); + Long post3Id = 포스트를_저장한다(mallangId, mallangBlogName, "안녕", "히히").getId(); PostSearchCond cond = PostSearchCond.builder() .title("안녕") .build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -446,15 +448,15 @@ class 포스트_검색_시 { @Test void 내용으로_조회() { // given - Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "안녕"); - Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "안녕하세요"); - Long post3Id = 포스트를_저장한다(mallangId, mallangBlogName, "안녕", "히히"); + Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "안녕").getId(); + Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "안녕하세요").getId(); + Long post3Id = 포스트를_저장한다(mallangId, mallangBlogName, "안녕", "히히").getId(); PostSearchCond cond = PostSearchCond.builder() .content("안녕") .build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -481,15 +483,15 @@ class 포스트_검색_시 { @Test void 내용_and_제목으로_조회() { // given - Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "안녕"); - Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "안녕하세요"); - Long post3Id = 포스트를_저장한다(mallangId, mallangBlogName, "안녕히", "히히"); + Long post1Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트1", "안녕").getId(); + Long post2Id = 포스트를_저장한다(mallangId, mallangBlogName, "포스트2", "안녕하세요").getId(); + Long post3Id = 포스트를_저장한다(mallangId, mallangBlogName, "안녕히", "히히").getId(); PostSearchCond cond = PostSearchCond.builder() .titleOrContent("안녕") .build(); // when - List responses = postQueryService.search(null, cond, pageable) + List responses = postQueryService.search(cond, pageable, null) .getContent(); // then @@ -529,7 +531,7 @@ class 포스트_검색_시 { // when & then assertThatThrownBy(() -> - postQueryService.search(null, cond, pageable) + postQueryService.search(cond, pageable, null) ).isInstanceOf(BadPostSearchCondException.class); } } diff --git a/src/test/java/com/mallang/post/query/PostStarQueryServiceTest.java b/src/test/java/com/mallang/post/query/PostStarQueryServiceTest.java index b2b5c5fb..474b02db 100644 --- a/src/test/java/com/mallang/post/query/PostStarQueryServiceTest.java +++ b/src/test/java/com/mallang/post/query/PostStarQueryServiceTest.java @@ -1,13 +1,13 @@ package com.mallang.post.query; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import com.mallang.common.ServiceTest; import com.mallang.post.application.command.StarPostCommand; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import com.mallang.post.query.response.StaredPostResponse; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -39,19 +39,22 @@ void setUp() { blogName, "포스트1", "내용1", - new PostVisibilityPolicy(PUBLIC, null)); + new PostVisibilityPolicy(PUBLIC, null) + ).getId(); post2Id = 포스트를_저장한다( memberId, blogName, "포스트2", "내용2", - new PostVisibilityPolicy(PUBLIC, null)); + new PostVisibilityPolicy(PUBLIC, null) + ).getId(); post3Id = 포스트를_저장한다( memberId, blogName, "포스트3", "내용3", - new PostVisibilityPolicy(PUBLIC, null)); + new PostVisibilityPolicy(PUBLIC, null) + ).getId(); } @Nested @@ -60,9 +63,9 @@ class 특정_회원의_즐겨찾기_목록_조회_시 { @Test void 누구나_볼_수_있다() { // given - postStarService.star(new StarPostCommand(post1Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post2Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post3Id, otherMemberId, null)); + postStarService.star(new StarPostCommand(post1Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post2Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post3Id, blogName, otherMemberId, null)); // when Page result = postStarQueryService.findAllByMemberId(otherMemberId, null, pageable); @@ -76,11 +79,11 @@ class 특정_회원의_즐겨찾기_목록_조회_시 { @Test void 보호_글은_보호되어_조회된다() { // given - postStarService.star(new StarPostCommand(post1Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post2Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post3Id, otherMemberId, null)); + postStarService.star(new StarPostCommand(post1Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post2Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post3Id, blogName, otherMemberId, null)); - 포스트_공개여부를_업데이트한다(memberId, post1Id, PROTECTED, "1234"); + 포스트_공개여부를_업데이트한다(memberId, post1Id, blogName, PROTECTED, "1234"); // when Page result = postStarQueryService.findAllByMemberId(otherMemberId, otherMemberId, @@ -95,11 +98,11 @@ class 특정_회원의_즐겨찾기_목록_조회_시 { @Test void 글_작성자가_다른_회원의_즐겨찾기_목록_조회_시_글_작성자의_보호글이_즐겨찾이_되어있다면_볼_수_있다() { // given - postStarService.star(new StarPostCommand(post1Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post2Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post3Id, otherMemberId, null)); + postStarService.star(new StarPostCommand(post1Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post2Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post3Id, blogName, otherMemberId, null)); - 포스트_공개여부를_업데이트한다(memberId, post1Id, PROTECTED, "1234"); + 포스트_공개여부를_업데이트한다(memberId, post1Id, blogName, PROTECTED, "1234"); // when Page result = postStarQueryService.findAllByMemberId(otherMemberId, memberId, pageable); @@ -113,11 +116,11 @@ class 특정_회원의_즐겨찾기_목록_조회_시 { @Test void 비공개_글은_누가_조회하든_조회되지_않는다() { // given - postStarService.star(new StarPostCommand(post1Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post2Id, otherMemberId, null)); - postStarService.star(new StarPostCommand(post3Id, otherMemberId, null)); + postStarService.star(new StarPostCommand(post1Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post2Id, blogName, otherMemberId, null)); + postStarService.star(new StarPostCommand(post3Id, blogName, otherMemberId, null)); - 포스트_공개여부를_업데이트한다(memberId, post1Id, PRIVATE, null); + 포스트_공개여부를_업데이트한다(memberId, post1Id, blogName, PRIVATE, null); // when Page result = postStarQueryService.findAllByMemberId(otherMemberId, memberId, pageable); diff --git a/src/test/java/com/mallang/post/query/dao/PostSearchDaoTest.java b/src/test/java/com/mallang/post/query/dao/PostSearchDaoTest.java index 73cce2ba..d7224d29 100644 --- a/src/test/java/com/mallang/post/query/dao/PostSearchDaoTest.java +++ b/src/test/java/com/mallang/post/query/dao/PostSearchDaoTest.java @@ -1,12 +1,12 @@ package com.mallang.post.query.dao; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PRIVATE; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PROTECTED; -import static com.mallang.post.domain.visibility.PostVisibilityPolicy.Visibility.PUBLIC; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PRIVATE; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PROTECTED; +import static com.mallang.post.domain.PostVisibilityPolicy.Visibility.PUBLIC; import static org.assertj.core.api.Assertions.assertThat; import com.mallang.common.ServiceTest; -import com.mallang.post.domain.visibility.PostVisibilityPolicy; +import com.mallang.post.domain.PostVisibilityPolicy; import com.mallang.post.query.dao.PostSearchDao.PostSearchCond; import com.mallang.post.query.response.PostSearchResponse; import java.util.List; @@ -41,13 +41,13 @@ void setUp() { new PostVisibilityPolicy(PRIVATE, null)); 포스트를_저장한다(otherId, otherBlogName, - "ohter-public", "content", + "other-public", "content", new PostVisibilityPolicy(PUBLIC, null)); 포스트를_저장한다(otherId, otherBlogName, - "ohter-protected", "content", + "other-protected", "content", new PostVisibilityPolicy(PROTECTED, "1234")); 포스트를_저장한다(otherId, otherBlogName, - "ohter-private", "content", + "other-private", "content", new PostVisibilityPolicy(PRIVATE, null)); } @@ -62,7 +62,7 @@ void setUp() { // then assertThat(search) .extracting(PostSearchResponse::title) - .containsExactly("ohter-protected", "ohter-public", + .containsExactly("other-protected", "other-public", "mallang-private", "mallang-protected", "mallang-public" ); } diff --git a/src/test/java/com/mallang/statistics/collector/PostViewHistoryAopTest.java b/src/test/java/com/mallang/statistics/collector/PostViewHistoryAopTest.java index 65925cc6..ec535e73 100644 --- a/src/test/java/com/mallang/statistics/collector/PostViewHistoryAopTest.java +++ b/src/test/java/com/mallang/statistics/collector/PostViewHistoryAopTest.java @@ -51,13 +51,13 @@ class PostViewHistoryAopTest extends ServiceTest { @Test void forJacocoTestCoverage() { - postViewHistoryAop.postQueryServiceGetById(); + postViewHistoryAop.postQueryServiceGetByIdAndBlogName(); } @Test - void 포인트컷으로_PostQueryService_의_getById_매칭() throws NoSuchMethodException { + void 포인트컷으로_PostQueryService_의_getByIdAndBlogName_매칭() throws NoSuchMethodException { // given - Method pointcut = PostViewHistoryAop.class.getDeclaredMethod("postQueryServiceGetById"); + Method pointcut = PostViewHistoryAop.class.getDeclaredMethod("postQueryServiceGetByIdAndBlogName"); Pointcut annotation = AnnotationUtils.getAnnotation(pointcut, Pointcut.class); String regex = "execution\\(\\* (.+?)\\(..\\)\\)"; Pattern pattern = Pattern.compile(regex); @@ -69,29 +69,29 @@ void forJacocoTestCoverage() { String group = matcher.group(1); // then - assertThat(group).isEqualTo(PostQueryService.class.getName() + ".getById"); + assertThat(group).isEqualTo(PostQueryService.class.getName() + ".getByIdAndBlogName"); } @Test - void PostQueryService_의_getById_외의_메서드가_호출되면_저장하지_않는다() { + void PostQueryService_의_getByIdAndBlogName_외의_메서드가_호출되면_저장하지_않는다() { // when - postQueryService.search(null, - new PostSearchCond(null, null, null, null, null, null, null), - PageRequest.of(0, 20)); + postQueryService.search(new PostSearchCond(null, null, null, null, null, null, null), PageRequest.of(0, 20), + null + ); // then verify(postViewHistoryCollector, times(0)).save(any()); } @Test - void PostQueryService_getById_시_기존_조회수_쿠키가_없다면_세팅한다() { + void PostQueryService_getByIdAndBlogName_시_기존_조회수_쿠키가_없다면_세팅한다() { // given Long memberId = 회원을_저장한다("말랑"); String blogName = 블로그_개설(memberId, "mallang-log"); - Long postId = 포스트를_저장한다(memberId, blogName, "안녕", "내용"); + Long postId = 포스트를_저장한다(memberId, blogName, "안녕", "내용").getId(); // when - postQueryService.getById(memberId, null, postId); + postQueryService.getByIdAndBlogName(postId, blogName, memberId, null); // then verify(postViewHistoryCollector, times(1)).save(any()); @@ -104,8 +104,8 @@ void forJacocoTestCoverage() { // given Long memberId = 회원을_저장한다("말랑"); String blogName = 블로그_개설(memberId, "mallang-log"); - Long postId = 포스트를_저장한다(memberId, blogName, "안녕", "내용"); - postQueryService.getById(memberId, null, postId); + Long postId = 포스트를_저장한다(memberId, blogName, "안녕", "내용").getId(); + postQueryService.getByIdAndBlogName(postId, blogName, memberId, null); // when Cookie postViewCookie = testHttpResponse().getCookie("POST_VIEW_COOKIE"); @@ -119,16 +119,16 @@ void forJacocoTestCoverage() { } @Test - void PostQueryService_getById_시_기존_조회수_쿠키가_있다면_별다른_설정을_하지_않는다() { + void PostQueryService_getByIdAndBlogName_시_기존_조회수_쿠키가_있다면_별다른_설정을_하지_않는다() { // given MockHttpServletRequest request = testHttpRequest(); request.setCookies(new Cookie("POST_VIEW_COOKIE", UUID.randomUUID().toString())); Long memberId = 회원을_저장한다("말랑"); String blogName = 블로그_개설(memberId, "mallang-log"); - Long postId = 포스트를_저장한다(memberId, blogName, "안녕", "내용"); + Long postId = 포스트를_저장한다(memberId, blogName, "안녕", "내용").getId(); // when - postQueryService.getById(memberId, null, postId); + postQueryService.getByIdAndBlogName(postId, blogName, memberId, null); // then verify(postViewHistoryCollector, times(1)).save(any()); @@ -140,7 +140,7 @@ void forJacocoTestCoverage() { void 조회_실패시_동작하지_않는다() { // when assertThatThrownBy(() -> { - postQueryService.getById(1L, null, 1000L); + postQueryService.getByIdAndBlogName(1000L, "name", 1L, null); }).isInstanceOf(NotFoundPostException.class); // then