From a8e58f5ed75fe3106a92ca10ca75785686a071a1 Mon Sep 17 00:00:00 2001 From: CodingLeeSeungHoon Date: Wed, 8 May 2024 01:00:24 +0900 Subject: [PATCH] feat : post domain search query dev, application & presentation layer deving (#53) --- .../post/application/DeletePostService.java | 2 +- .../ExposurePostToStarPageMainService.java | 2 +- .../post/application/HostHeartService.java | 2 +- .../post/application/LikePostService.java | 2 +- .../ModifyPostInformationService.java | 2 +- .../PostByCategoryViewService.java | 37 ++++ .../application/PostDetailViewService.java | 62 ++++++ .../post/application/PostServiceHelper.java | 6 +- .../post/application/PostUseCase.java | 11 - .../post/application/PostUseCaseImpl.java | 50 ----- .../post/application/RestorePostService.java | 2 +- .../post/application/WritePostService.java | 44 +++- .../dto/CommonPostParagraphDto.java | 13 ++ .../post/application/dto/PostDetailDto.java | 37 ++++ .../dto/VoteAblePostOptionDetailDto.java | 10 + .../needeachother/post/domain/AlbumImage.java | 1 + .../needeachother/post/domain/AlbumPost.java | 17 ++ .../needeachother/post/domain/CommonPost.java | 18 ++ .../post/domain/CommonPostParagraph.java | 12 + .../post/domain/GoldBalancePost.java | 26 +++ .../post/domain/LeftRightRate.java | 6 +- .../post/domain/PostCustomRepository.java | 4 - .../post/domain/PostRepository.java | 8 - .../post/domain/StarPagePost.java | 5 + .../needeachother/post/domain/VoteItem.java | 1 + .../needeachother/post/domain/VotePost.java | 32 ++- .../post/domain/dto/PostSearchCondition.java | 26 +++ .../domain/dto/StarPagePostHeadlineDto.java | 24 ++ .../domain/repository/PostRepository.java | 13 ++ .../repository/PostRepositoryCustom.java | 23 ++ .../post/infra/PostCustomRepositoryImpl.java | 10 - .../post/infra/PostRepositoryImpl.java | 206 ++++++++++++++++++ .../presentation/PostFeatureController.java | 35 +++ .../presentation/PostStatusController.java | 25 +++ .../post/presentation/PostViewController.java | 65 ++++++ .../presentation/PostWriteController.java | 71 ++++++ .../dto/CommonPostParagraphRequest.java | 13 ++ .../dto/GetPostPageByCategoryRequest.java | 16 ++ .../dto/WriteAlbumPostRequest.java | 16 ++ .../dto/WriteCommonPostRequest.java | 18 ++ .../dto/WriteGoldBalancePostRequest.java | 18 ++ .../dto/WriteVotePostRequest.java | 20 ++ .../CategoryCustomRepositoryImplTest.java | 4 +- .../post/infra/PostRepositoryImplTest.java | 159 ++++++++++++++ .../infra/StarPageRepositoryImplTest.java | 7 +- 45 files changed, 1071 insertions(+), 110 deletions(-) create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/application/PostByCategoryViewService.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/application/PostDetailViewService.java delete mode 100644 needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCase.java delete mode 100644 needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCaseImpl.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/application/dto/CommonPostParagraphDto.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/application/dto/PostDetailDto.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/application/dto/VoteAblePostOptionDetailDto.java delete mode 100644 needeachother/src/main/java/com/neo/needeachother/post/domain/PostCustomRepository.java delete mode 100644 needeachother/src/main/java/com/neo/needeachother/post/domain/PostRepository.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/domain/dto/PostSearchCondition.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/domain/dto/StarPagePostHeadlineDto.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepository.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepositoryCustom.java delete mode 100644 needeachother/src/main/java/com/neo/needeachother/post/infra/PostCustomRepositoryImpl.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/infra/PostRepositoryImpl.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/PostFeatureController.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/PostStatusController.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/PostViewController.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/PostWriteController.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/CommonPostParagraphRequest.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/GetPostPageByCategoryRequest.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteAlbumPostRequest.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteCommonPostRequest.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteGoldBalancePostRequest.java create mode 100644 needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteVotePostRequest.java create mode 100644 needeachother/src/test/java/com/neo/needeachother/post/infra/PostRepositoryImplTest.java diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/DeletePostService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/DeletePostService.java index 97d2352..8c1d588 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/DeletePostService.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/DeletePostService.java @@ -1,6 +1,6 @@ package com.neo.needeachother.post.application; -import com.neo.needeachother.post.domain.PostRepository; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.post.domain.StarPagePost; import com.neo.needeachother.post.domain.domainservice.PostFeatureUseAbleQualificationService; import lombok.RequiredArgsConstructor; diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/ExposurePostToStarPageMainService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/ExposurePostToStarPageMainService.java index 02ab52d..c9a99b7 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/ExposurePostToStarPageMainService.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/ExposurePostToStarPageMainService.java @@ -1,6 +1,6 @@ package com.neo.needeachother.post.application; -import com.neo.needeachother.post.domain.PostRepository; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.post.domain.StarPagePost; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/HostHeartService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/HostHeartService.java index 524405c..1d1d3c1 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/HostHeartService.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/HostHeartService.java @@ -1,6 +1,6 @@ package com.neo.needeachother.post.application; -import com.neo.needeachother.post.domain.PostRepository; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.post.domain.StarPagePost; import com.neo.needeachother.post.domain.domainservice.PostFeatureUseAbleQualificationService; import lombok.RequiredArgsConstructor; diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/LikePostService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/LikePostService.java index 243d42d..f3543b2 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/LikePostService.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/LikePostService.java @@ -1,6 +1,6 @@ package com.neo.needeachother.post.application; -import com.neo.needeachother.post.domain.PostRepository; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.post.domain.StarPagePost; import com.neo.needeachother.post.domain.domainservice.PostFeatureUseAbleQualificationService; import lombok.RequiredArgsConstructor; diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/ModifyPostInformationService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/ModifyPostInformationService.java index a1962ae..70d167b 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/ModifyPostInformationService.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/ModifyPostInformationService.java @@ -1,6 +1,6 @@ package com.neo.needeachother.post.application; -import com.neo.needeachother.post.domain.PostRepository; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.post.domain.StarPagePost; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/PostByCategoryViewService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/PostByCategoryViewService.java new file mode 100644 index 0000000..27fe3c0 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/PostByCategoryViewService.java @@ -0,0 +1,37 @@ +package com.neo.needeachother.post.application; + +import com.neo.needeachother.category.domain.CategoryId; +import com.neo.needeachother.post.domain.dto.PostSearchCondition; +import com.neo.needeachother.post.domain.dto.StarPagePostHeadlineDto; +import com.neo.needeachother.post.domain.repository.PostRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PostByCategoryViewService { + + private final PostRepository postRepository; + + public Slice getPostPageByCategoryWithInfiniteScroll(String categoryId, Long lastPostId, Pageable pageable, + boolean orderByCreatedAt, boolean orderByLikeCount, boolean onlySearchHostWritten, boolean onlySearchHostHearted) { + + return postRepository.searchPostHeadlineByCategoryIdWithNoOffset( + CategoryId.of(categoryId), + PostSearchCondition.of(orderByCreatedAt, orderByLikeCount, onlySearchHostWritten, onlySearchHostHearted), + lastPostId, + pageable); + } + + public Page getPostPageByCategoryWithPaging(String categoryId, Pageable pageable, + boolean orderByCreatedAt, boolean orderByLikeCount, boolean onlySearchHostWritten, boolean onlySearchHostHearted) { + return postRepository.searchPostHeadlineByCategoryIdWithPaging( + CategoryId.of(categoryId), + PostSearchCondition.of(orderByCreatedAt, orderByLikeCount, onlySearchHostWritten, onlySearchHostHearted), + pageable + ); + } +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/PostDetailViewService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/PostDetailViewService.java new file mode 100644 index 0000000..4935798 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/PostDetailViewService.java @@ -0,0 +1,62 @@ +package com.neo.needeachother.post.application; + +import com.neo.needeachother.common.exception.NEOUnexpectedException; +import com.neo.needeachother.post.application.dto.PostDetailDto; +import com.neo.needeachother.post.domain.*; +import com.neo.needeachother.post.domain.repository.PostRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PostDetailViewService { + + private final PostRepository postRepository; + + public PostDetailDto getPostDetailView(String contentType, Long postId) { + PostType postType = PostType.valueOf(contentType); + switch (postType) { + case COMMON -> { + return getCommonPostDetailView(postId); + } + case ALBUM -> { + return getAlbumPostDetailView(postId); + } + case GOLD_BALANCE -> { + return getGoldBalancePostDetailView(postId); + } + case VOTE -> { + return getVotePostDetailView(postId); + } + default -> throw new NEOUnexpectedException("적절하지 않은 컨텐츠 타입의 입력"); + } + } + + private PostDetailDto getCommonPostDetailView(Long postId) { + return postRepository.findCommonPostById(postId) + .map(CommonPost::toPostDetailDto) + // TODO : orElseThrow로 변경 + .orElse(null); + } + + private PostDetailDto getAlbumPostDetailView(Long postId) { + return postRepository.findAlbumPostById(postId) + .map(AlbumPost::toPostDetailDto) + // TODO : orElseThrow로 변경 + .orElse(null); + } + + private PostDetailDto getGoldBalancePostDetailView(Long postId) { + return postRepository.findGoldBalancePostById(postId) + .map(GoldBalancePost::toPostDetailDto) + // TODO : orElseThrow로 변경 + .orElse(null); + } + + private PostDetailDto getVotePostDetailView(Long postId) { + return postRepository.findVotePostById(postId) + .map(VotePost::toPostDetailDto) + // TODO : orElseThrow로 변경 + .orElse(null); + } +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/PostServiceHelper.java b/needeachother/src/main/java/com/neo/needeachother/post/application/PostServiceHelper.java index 67b036f..8e6718c 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/PostServiceHelper.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/PostServiceHelper.java @@ -2,6 +2,9 @@ import com.neo.needeachother.common.exception.NEOUnexpectedException; import com.neo.needeachother.post.domain.*; +import com.neo.needeachother.post.domain.repository.PostRepository; + +import java.util.Optional; public final class PostServiceHelper { public static CommonPost findExistingCommonPost(PostRepository repository, Long postId){ @@ -37,7 +40,8 @@ public static VotePost findExistingVotePost(PostRepository repository, Long post } public static StarPagePost findExistingStarPagePost(PostRepository repository, Long postId){ - return repository.findById(postId) + repository.findById(postId); + return repository.findById(postId) .orElseThrow(() -> new NEOUnexpectedException("포스트 아이디와 매칭되는 포스트가 없습니다.")); } } diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCase.java b/needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCase.java deleted file mode 100644 index 702e9c9..0000000 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCase.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.neo.needeachother.post.application; - -public interface PostUseCase { - void giveHostHeart(Long postId, String email); - void retrieveHostHeart(Long postId, String email); - void likeIt(Long postId, String email); - void unLikeIt(Long postId, String email); - void restorePost(Long postId, String email); - void deletePost(Long postId, String email); - void posting(); -} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCaseImpl.java b/needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCaseImpl.java deleted file mode 100644 index 59e7ca4..0000000 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/PostUseCaseImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.neo.needeachother.post.application; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class PostUseCaseImpl implements PostUseCase{ - - private final HostHeartService hostHeartService; - private final LikePostService likePostService; - private final RestorePostService restorePostService; - private final DeletePostService deletePostService; - - @Override - public void giveHostHeart(Long postId, String email) { - hostHeartService.giveHostHeart(postId, email); - } - - @Override - public void retrieveHostHeart(Long postId, String email) { - hostHeartService.retrieveHostHeart(postId, email); - } - - @Override - public void likeIt(Long postId, String email) { - likePostService.likeIt(postId, email); - } - - @Override - public void unLikeIt(Long postId, String email) { - likePostService.unLikeIt(postId, email); - } - - @Override - public void restorePost(Long postId, String email) { - restorePostService.restorePost(postId, email); - } - - @Override - public void deletePost(Long postId, String email) { - deletePostService.deletePost(postId, email); - } - - @Override - public void posting(){ - - } - -} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/RestorePostService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/RestorePostService.java index 1e9a93e..105c64d 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/RestorePostService.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/RestorePostService.java @@ -1,6 +1,6 @@ package com.neo.needeachother.post.application; -import com.neo.needeachother.post.domain.PostRepository; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.post.domain.StarPagePost; import com.neo.needeachother.post.domain.domainservice.PostFeatureUseAbleQualificationService; import lombok.RequiredArgsConstructor; diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/WritePostService.java b/needeachother/src/main/java/com/neo/needeachother/post/application/WritePostService.java index 4c22ffc..67ce864 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/application/WritePostService.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/WritePostService.java @@ -1,11 +1,10 @@ package com.neo.needeachother.post.application; import com.neo.needeachother.category.domain.CategoryId; -import com.neo.needeachother.post.domain.Author; -import com.neo.needeachother.post.domain.CommonPost; -import com.neo.needeachother.post.domain.CommonPostParagraph; -import com.neo.needeachother.post.domain.PostRepository; +import com.neo.needeachother.post.domain.*; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.post.domain.domainservice.CreatePostByCategoryService; +import com.neo.needeachother.post.presentation.dto.CommonPostParagraphRequest; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,10 +19,43 @@ public class WritePostService { private final CreatePostByCategoryService createPostByCategoryService; @Transactional - public void writeCommonPost(String title, Author author, CategoryId categoryId, List paragraphs){ - CommonPost createdCommonPost = createPostByCategoryService.createCommonPost(title, author, categoryId, paragraphs); + public void writeCommonPost(String title, String authorName, String authorEmail, String categoryId, List paragraphs) { + CommonPost createdCommonPost = createPostByCategoryService.createCommonPost( + title, + Author.of(authorName, authorEmail), + CategoryId.of(categoryId), + paragraphs.stream() + .map(paragraph -> CommonPostParagraph.of(paragraph.getBody(), paragraph.getParagraphType())) + .toList()); postRepository.save(createdCommonPost); } + @Transactional + public void writeAlbumPost(String title, String authorName, String authorEmail, String categoryId, String imagePath) { + AlbumPost createdAlbumPost = createPostByCategoryService.createAlbumPost( + title, Author.of(authorName, authorEmail), AlbumImage.of(imagePath), CategoryId.of(categoryId)); + postRepository.save(createdAlbumPost); + } + + @Transactional + public void writeGoldBalancePost(String title, String authorName, String authorEmail, String categoryId, String question, + String leftExample, String rightExample) { + GoldBalancePost createdGoldBalancePost = createPostByCategoryService.createGoldBalancePost( + title, Author.of(authorName, authorEmail), question, leftExample, rightExample, CategoryId.of(categoryId)); + postRepository.save(createdGoldBalancePost); + } + @Transactional + public void writeVotePost(String title, String authorName, String authorEmail, String categoryId, String question, + int timeToLive, List voteOptionNameList) { + + List voteItemList = voteOptionNameList.stream() + .map(VoteItem::of) + .toList(); + + VotePost createdVotePost = createPostByCategoryService.createVotePost( + title, Author.of(authorName, authorEmail), question, timeToLive, voteItemList, CategoryId.of(categoryId)); + + postRepository.save(createdVotePost); + } } diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/dto/CommonPostParagraphDto.java b/needeachother/src/main/java/com/neo/needeachother/post/application/dto/CommonPostParagraphDto.java new file mode 100644 index 0000000..6f514b1 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/dto/CommonPostParagraphDto.java @@ -0,0 +1,13 @@ +package com.neo.needeachother.post.application.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class CommonPostParagraphDto { + private String paragraphType; + private String body; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/dto/PostDetailDto.java b/needeachother/src/main/java/com/neo/needeachother/post/application/dto/PostDetailDto.java new file mode 100644 index 0000000..6ea5414 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/dto/PostDetailDto.java @@ -0,0 +1,37 @@ +package com.neo.needeachother.post.application.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class PostDetailDto { + + private Long postId; + private String categoryId; + private String title; + private String authorName; + private String status; + private int likeCount; + private boolean hostHeart; + private LocalDateTime exposureAt; + private String postType; + + /* common & image post data */ + private String representativeImage; + + /* only common post data */ + private List paragraph; + + /* GoldBalance, Vote post data */ + private String question; + private Map options; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/application/dto/VoteAblePostOptionDetailDto.java b/needeachother/src/main/java/com/neo/needeachother/post/application/dto/VoteAblePostOptionDetailDto.java new file mode 100644 index 0000000..030a1bb --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/application/dto/VoteAblePostOptionDetailDto.java @@ -0,0 +1,10 @@ +package com.neo.needeachother.post.application.dto; + +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class VoteAblePostOptionDetailDto { + private String optionName; + private Integer optionCount; + private Integer optionRate; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumImage.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumImage.java index e2f2d77..e02ffad 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumImage.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumImage.java @@ -10,6 +10,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class AlbumImage { + @Getter(value = AccessLevel.PROTECTED) @Column(name = "image_path") private String path; diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumPost.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumPost.java index 7bd0fad..13de732 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumPost.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/AlbumPost.java @@ -2,6 +2,7 @@ import com.neo.needeachother.category.domain.CategoryId; import com.neo.needeachother.category.domain.ContentType; +import com.neo.needeachother.post.application.dto.PostDetailDto; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -29,4 +30,20 @@ public AlbumPost of(CategoryId categoryId, String title, Author author, PostStat AlbumImage albumImage){ return new AlbumPost(categoryId, title, author, status, albumImage); } + + @Override + public PostDetailDto toPostDetailDto() { + return PostDetailDto.builder() + .postId(this.getId()) + .categoryId(this.getCategoryId().getValue()) + .title(this.getTitle()) + .authorName(this.getAuthor().getAuthorName()) + .status(this.getStatus().name()) + .likeCount(this.getLikeCount()) + .hostHeart(this.isHostHeart()) + .exposureAt(this.getExposureAt()) + .postType(this.getPostType().name()) + .representativeImage(this.image.getPath()) + .build(); + } } diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPost.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPost.java index 027dee2..77dda9b 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPost.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPost.java @@ -2,6 +2,7 @@ import com.neo.needeachother.category.domain.CategoryId; import com.neo.needeachother.category.domain.ContentType; +import com.neo.needeachother.post.application.dto.PostDetailDto; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; @@ -43,4 +44,21 @@ public void changeCommonPostContents(List modifiedContents) commonPostContents.clear(); commonPostContents = modifiedContents; } + + @Override + public PostDetailDto toPostDetailDto() { + return PostDetailDto.builder() + .postId(this.getId()) + .categoryId(this.getCategoryId().getValue()) + .title(this.getTitle()) + .authorName(this.getAuthor().getAuthorName()) + .status(this.getStatus().name()) + .likeCount(this.getLikeCount()) + .hostHeart(this.isHostHeart()) + .exposureAt(this.getExposureAt()) + .postType(this.getPostType().name()) + .paragraph(this.commonPostContents.stream().map(CommonPostParagraph::toDto).toList()) + .representativeImage(this.representativeImage) + .build(); + } } diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPostParagraph.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPostParagraph.java index 9d48de3..a2e9c22 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPostParagraph.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/CommonPostParagraph.java @@ -1,5 +1,6 @@ package com.neo.needeachother.post.domain; +import com.neo.needeachother.post.application.dto.CommonPostParagraphDto; import com.neo.needeachother.post.infra.CommonPostParagraphTypeConverter; import jakarta.persistence.*; import lombok.*; @@ -18,6 +19,10 @@ public class CommonPostParagraph { @Convert(converter = CommonPostParagraphTypeConverter.class) private CommonPostParagraphType commonPostContentType; + public static CommonPostParagraph of(String textOrPath, String type){ + return new CommonPostParagraph(textOrPath, CommonPostParagraphType.valueOf(type)); + } + public static CommonPostParagraph ofTextParagraph(String text){ return new CommonPostParagraph(text, CommonPostParagraphType.TEXT); } @@ -25,4 +30,11 @@ public static CommonPostParagraph ofTextParagraph(String text){ public static CommonPostParagraph ofImageParagraph(String imgPath){ return new CommonPostParagraph(imgPath, CommonPostParagraphType.IMAGE); } + + public CommonPostParagraphDto toDto(){ + return CommonPostParagraphDto.builder() + .body(this.body) + .paragraphType(this.commonPostContentType.name()) + .build(); + } } diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/GoldBalancePost.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/GoldBalancePost.java index 4424768..0edd8a6 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/GoldBalancePost.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/GoldBalancePost.java @@ -2,11 +2,16 @@ import com.neo.needeachother.category.domain.CategoryId; import com.neo.needeachother.category.domain.ContentType; +import com.neo.needeachother.post.application.dto.PostDetailDto; +import com.neo.needeachother.post.application.dto.VoteAblePostOptionDetailDto; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.HashMap; +import java.util.Map; + @Getter @Entity @Table(name = "star_page_gold_balance_post") @@ -34,6 +39,27 @@ public GoldBalancePost(CategoryId categoryId, String title, Author author, PostS this.leftRightRate = this.calculateAnswerRate(); } + @Override + public PostDetailDto toPostDetailDto() { + Map voteOptionMap = new HashMap<>(); + voteOptionMap.put("left", new VoteAblePostOptionDetailDto(this.leftDetail.getLeftExample(), + this.leftDetail.getLeftAnswersCount(), this.leftRightRate.getLeftRate())); + voteOptionMap.put("right", new VoteAblePostOptionDetailDto(this.rightDetail.getRightExample(), + this.rightDetail.getRightAnswersCount(), this.leftRightRate.getRightRate())); + return PostDetailDto.builder() + .postId(this.getId()) + .categoryId(this.getCategoryId().getValue()) + .title(this.getTitle()) + .authorName(this.getAuthor().getAuthorName()) + .status(this.getStatus().name()) + .likeCount(this.getLikeCount()) + .hostHeart(this.isHostHeart()) + .exposureAt(this.getExposureAt()) + .postType(this.getPostType().name()) + .question(this.getQuestion()) + .options(voteOptionMap) + .build(); + } // 도메인 : 황밸 게시글은 좌측 답변을 선택할 수 있다. public void chooseLeftAnswer(String email) { diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/LeftRightRate.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/LeftRightRate.java index 3f76c95..175f61f 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/LeftRightRate.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/LeftRightRate.java @@ -1,11 +1,9 @@ package com.neo.needeachother.post.domain; import jakarta.persistence.Embeddable; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; +import lombok.*; +@Getter @Embeddable @EqualsAndHashCode @AllArgsConstructor diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/PostCustomRepository.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/PostCustomRepository.java deleted file mode 100644 index 4d6d3a2..0000000 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/PostCustomRepository.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.neo.needeachother.post.domain; - -public interface PostCustomRepository { -} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/PostRepository.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/PostRepository.java deleted file mode 100644 index 5f0c283..0000000 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/PostRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.neo.needeachother.post.domain; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PostRepository extends JpaRepository, PostCustomRepository { -} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/StarPagePost.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/StarPagePost.java index a90ab86..23edd91 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/StarPagePost.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/StarPagePost.java @@ -3,11 +3,13 @@ import com.neo.needeachother.category.domain.CategoryId; import com.neo.needeachother.common.entity.NEOTimeDefaultEntity; import com.neo.needeachother.common.exception.NEOUnexpectedException; +import com.neo.needeachother.post.application.dto.PostDetailDto; import com.neo.needeachother.post.domain.domainservice.PostFeatureUseAbleQualificationService; import com.neo.needeachother.post.infra.PostStatusConverter; import com.neo.needeachother.post.infra.PostTypeConverter; import jakarta.persistence.*; import lombok.AccessLevel; +import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -17,6 +19,7 @@ @Entity @Table(name = "star_page_post") +@Getter(value = AccessLevel.PROTECTED) @Inheritance(strategy = InheritanceType.JOINED) @NoArgsConstructor(access = AccessLevel.PROTECTED) public abstract class StarPagePost extends NEOTimeDefaultEntity { @@ -68,6 +71,8 @@ public StarPagePost(CategoryId categoryId, String title, Author author, PostStat this.postType = postType; } + public abstract PostDetailDto toPostDetailDto(); + private boolean isAlreadyLikedBy(String email) { return likes.contains(PostLike.of(email)); } diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/VoteItem.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/VoteItem.java index fce66f2..c1f3e59 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/VoteItem.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/VoteItem.java @@ -10,6 +10,7 @@ @Table(name = "vote_item") @EqualsAndHashCode @AllArgsConstructor +@Getter(value = AccessLevel.PROTECTED) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class VoteItem { diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/VotePost.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/VotePost.java index dd9b9d6..7a9fe45 100644 --- a/needeachother/src/main/java/com/neo/needeachother/post/domain/VotePost.java +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/VotePost.java @@ -3,15 +3,21 @@ import com.neo.needeachother.category.domain.CategoryId; import com.neo.needeachother.category.domain.ContentType; import com.neo.needeachother.common.exception.NEOUnexpectedException; +import com.neo.needeachother.post.application.dto.PostDetailDto; +import com.neo.needeachother.post.application.dto.VoteAblePostOptionDetailDto; import jakarta.persistence.*; import lombok.AccessLevel; +import lombok.Getter; import lombok.NoArgsConstructor; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Entity @Table(name = "star_page_vote_post") +@Getter(value = AccessLevel.PROTECTED) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class VotePost extends StarPagePost { @@ -39,6 +45,30 @@ public VotePost(CategoryId categoryId, String title, Author author, PostStatus s this.voteItems = voteItems; } + @Override + public PostDetailDto toPostDetailDto() { + Map voteOptionMap = new HashMap<>(); + for (int i = 0; i < voteItems.size(); i++) { + VoteItem nowVoteItem = this.voteItems.get(i); + voteOptionMap.put(String.valueOf(i), + new VoteAblePostOptionDetailDto(nowVoteItem.getOptionText(), + nowVoteItem.getVoterSet().size(), null)); + } + return PostDetailDto.builder() + .postId(this.getId()) + .categoryId(this.getCategoryId().getValue()) + .title(this.getTitle()) + .authorName(this.getAuthor().getAuthorName()) + .status(this.getStatus().name()) + .likeCount(this.getLikeCount()) + .hostHeart(this.isHostHeart()) + .exposureAt(this.getExposureAt()) + .postType(this.getPostType().name()) + .question(this.getQuestion()) + .options(voteOptionMap) + .build(); + } + public void changeQuestion(String email, String question) { this.canChangeVotePostElement(); this.isAuthor(email); @@ -62,7 +92,7 @@ public void voteByOptionIdx(String email, Voter voter, int idx) { this.voteItems.get(idx).vote(voter); } - private void checkVoteOptionsOOB(int idx){ + private void checkVoteOptionsOOB(int idx) { if (this.voteItems.size() <= idx) { throw new NEOUnexpectedException("투표 항목 인덱스가 범위를 벗어남."); } diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/dto/PostSearchCondition.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/dto/PostSearchCondition.java new file mode 100644 index 0000000..6586c3c --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/dto/PostSearchCondition.java @@ -0,0 +1,26 @@ +package com.neo.needeachother.post.domain.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class PostSearchCondition { + private boolean orderByCreatedAt; + private boolean orderByLikeCount; + private boolean onlySearchHostWritten; + private boolean onlySearchHostHearted; + + public static PostSearchCondition of(boolean orderByCreatedAt, boolean orderByLikeCount, + boolean onlySearchHostWritten, boolean onlySearchHostHearted){ + return PostSearchCondition.builder() + .orderByCreatedAt(orderByCreatedAt) + .orderByLikeCount(orderByLikeCount) + .onlySearchHostWritten(onlySearchHostWritten) + .onlySearchHostHearted(onlySearchHostHearted) + .build(); + } + +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/dto/StarPagePostHeadlineDto.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/dto/StarPagePostHeadlineDto.java new file mode 100644 index 0000000..fda68ff --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/dto/StarPagePostHeadlineDto.java @@ -0,0 +1,24 @@ +package com.neo.needeachother.post.domain.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.ToString; + +import java.time.LocalDateTime; + +@Getter +@ToString +@RequiredArgsConstructor +public class StarPagePostHeadlineDto { + private final String categoryId; + private final String categoryTitle; + private final Long postId; + private final int likeCount; + private final String authorName; + private final String postTitle; + private final LocalDateTime createdAt; + private final boolean hostHearted; + private final String postType; + private final String status; + private final boolean isChanged; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepository.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepository.java new file mode 100644 index 0000000..39616e5 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepository.java @@ -0,0 +1,13 @@ +package com.neo.needeachother.post.domain.repository; + +import com.neo.needeachother.post.domain.CommonPost; +import com.neo.needeachother.post.domain.StarPagePost; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +public interface PostRepository extends JpaRepository, PostRepositoryCustom { +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepositoryCustom.java b/needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepositoryCustom.java new file mode 100644 index 0000000..6cd3e60 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/domain/repository/PostRepositoryCustom.java @@ -0,0 +1,23 @@ +package com.neo.needeachother.post.domain.repository; + +import com.neo.needeachother.category.domain.CategoryId; +import com.neo.needeachother.post.domain.AlbumPost; +import com.neo.needeachother.post.domain.CommonPost; +import com.neo.needeachother.post.domain.GoldBalancePost; +import com.neo.needeachother.post.domain.VotePost; +import com.neo.needeachother.post.domain.dto.PostSearchCondition; +import com.neo.needeachother.post.domain.dto.StarPagePostHeadlineDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; + +import java.util.Optional; + +public interface PostRepositoryCustom { + Page searchPostHeadlineByCategoryIdWithPaging(CategoryId categoryId, PostSearchCondition postSearchCondition, Pageable pageable); + Slice searchPostHeadlineByCategoryIdWithNoOffset(CategoryId categoryId, PostSearchCondition postSearchCondition, Long lastPostId, Pageable pageable); + Optional findCommonPostById(Long postId); + Optional findAlbumPostById(Long postId); + Optional findGoldBalancePostById(Long postId); + Optional findVotePostById(Long postId); +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/infra/PostCustomRepositoryImpl.java b/needeachother/src/main/java/com/neo/needeachother/post/infra/PostCustomRepositoryImpl.java deleted file mode 100644 index a8a9077..0000000 --- a/needeachother/src/main/java/com/neo/needeachother/post/infra/PostCustomRepositoryImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.neo.needeachother.post.infra; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class PostCustomRepositoryImpl { - - private final JPAQueryFactory jpaQueryFactory; -} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/infra/PostRepositoryImpl.java b/needeachother/src/main/java/com/neo/needeachother/post/infra/PostRepositoryImpl.java new file mode 100644 index 0000000..70a41f5 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/infra/PostRepositoryImpl.java @@ -0,0 +1,206 @@ +package com.neo.needeachother.post.infra; + +import com.neo.needeachother.category.domain.CategoryId; +import com.neo.needeachother.post.domain.*; +import com.neo.needeachother.post.domain.dto.PostSearchCondition; +import com.neo.needeachother.post.domain.dto.StarPagePostHeadlineDto; +import com.neo.needeachother.post.domain.repository.PostRepositoryCustom; +import com.querydsl.core.types.Order; +import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; +import org.springframework.data.support.PageableExecutionUtils; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import static com.neo.needeachother.post.domain.QAlbumPost.albumPost; +import static com.neo.needeachother.post.domain.QCommonPost.commonPost; +import static com.neo.needeachother.post.domain.QGoldBalancePost.goldBalancePost; +import static com.neo.needeachother.post.domain.QStarPagePost.starPagePost; +import static com.neo.needeachother.category.domain.QCategory.category; +import static com.neo.needeachother.post.domain.QVoteItem.voteItem; +import static com.neo.needeachother.post.domain.QVotePost.votePost; +import static com.neo.needeachother.starpage.domain.QStarPage.starPage; + +@Repository +@RequiredArgsConstructor +public class PostRepositoryImpl implements PostRepositoryCustom { + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public Page searchPostHeadlineByCategoryIdWithPaging(CategoryId categoryId, PostSearchCondition postSearchCondition, Pageable pageable) { + List content = jpaQueryFactory.select( + Projections.constructor(StarPagePostHeadlineDto.class, + Expressions.asString(categoryId.getValue()).as("categoryId"), + category.categoryInformation.categoryTitle, + starPagePost.id, + starPagePost.likeCount, + starPagePost.author.authorName, + starPagePost.title, + starPagePost.createdAt, + starPagePost.hostHeart, + starPagePost.postType.stringValue(), + starPagePost.status.stringValue(), + Expressions.asBoolean(starPagePost.createdAt.ne(starPagePost.updatedAt)).as("isChanged") + ) + + ) + .from(starPagePost) + .innerJoin(category).on(starPagePost.categoryId.eq(category.categoryId)) + .innerJoin(starPage).on(category.starPageId.eq(starPage.starPageId)) + .where( + postEqCategoryId(categoryId), + postEqHostHearted(postSearchCondition), + postAuthorEqHost(postSearchCondition) + ) + .orderBy(orderBySearchCondition(postSearchCondition)) + .limit(pageable.getPageSize()) + .offset(pageable.getOffset()) + .fetch(); + + JPAQuery countQuery = + jpaQueryFactory.select(starPagePost.count()) + .from(starPagePost) + .where(postEqCategoryId(categoryId)); + + return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne); + } + + @Override + public Slice searchPostHeadlineByCategoryIdWithNoOffset(CategoryId categoryId, PostSearchCondition postSearchCondition, Long lastPostId, Pageable pageable) { + List content = jpaQueryFactory.select( + Projections.constructor(StarPagePostHeadlineDto.class, + Expressions.asString(categoryId.getValue()).as("categoryId"), + category.categoryInformation.categoryTitle, + starPagePost.id, + starPagePost.likeCount, + starPagePost.author.authorName, + starPagePost.title, + starPagePost.createdAt, + starPagePost.hostHeart, + starPagePost.postType.stringValue(), + starPagePost.status.stringValue(), + Expressions.asBoolean(starPagePost.createdAt.ne(starPagePost.updatedAt)).as("isChanged") + ) + + ) + .from(starPagePost) + .innerJoin(category).on(starPagePost.categoryId.eq(category.categoryId)) + .innerJoin(starPage).on(category.starPageId.eq(starPage.starPageId)) + .where( + postLessThanLastPostId(lastPostId), + postEqCategoryId(categoryId), + postEqHostHearted(postSearchCondition), + postAuthorEqHost(postSearchCondition) + ) + .orderBy(orderBySearchCondition(postSearchCondition)) + .limit(pageable.getPageSize() + 1) + .offset(pageable.getOffset()) + .fetch(); + + boolean hasNext = false; + if (content.size() > pageable.getPageSize()) { + hasNext = true; + content.remove(pageable.getPageSize()); + } + + return new SliceImpl<>(content, pageable, hasNext); + } + + @Override + public Optional findCommonPostById(Long postId){ + return Optional.ofNullable( + jpaQueryFactory.select(commonPost) + .from(commonPost) + .innerJoin(commonPost.commonPostContents).fetchJoin() + .where(commonPost.id.eq(postId)) + .fetchOne() + ); + } + + @Override + public Optional findAlbumPostById(Long postId){ + return Optional.ofNullable( + jpaQueryFactory.select(albumPost) + .from(albumPost) + .where(albumPost.id.eq(postId)) + .fetchOne() + ); + } + + @Override + public Optional findGoldBalancePostById(Long postId){ + return Optional.ofNullable( + jpaQueryFactory.select(goldBalancePost) + .from(goldBalancePost) + .where(goldBalancePost.id.eq(postId)) + .fetchOne() + ); + } + + @Override + public Optional findVotePostById(Long postId){ + return Optional.ofNullable( + jpaQueryFactory.select(votePost) + .from(votePost) + .innerJoin(votePost.voteItems, voteItem).fetchJoin() + .where(votePost.id.eq(postId)) + .fetchOne() + ); + } + + private OrderSpecifier[] orderBySearchCondition(PostSearchCondition postSearchCondition) { + + List orderSpecifiers = new ArrayList<>(); + if (Objects.isNull(postSearchCondition)) { + orderSpecifiers.add(new OrderSpecifier(Order.DESC, starPagePost.createdAt)); + return orderSpecifiers.toArray(new OrderSpecifier[0]); + } + + if (postSearchCondition.isOrderByCreatedAt()) { + orderSpecifiers.add(new OrderSpecifier(Order.DESC, starPagePost.createdAt)); + } + + if (postSearchCondition.isOrderByLikeCount()) { + orderSpecifiers.add(new OrderSpecifier(Order.DESC, starPagePost.likeCount)); + } + + return orderSpecifiers.toArray(new OrderSpecifier[0]); + } + + private BooleanExpression postEqCategoryId(CategoryId categoryId) { + return starPagePost.categoryId.eq(categoryId); + } + + private BooleanExpression postLessThanLastPostId(Long postId) { + return starPagePost.id.lt(postId); + } + + private BooleanExpression postEqHostHearted(PostSearchCondition postSearchCondition) { + if (Objects.isNull(postSearchCondition)) { + return null; + } + return postSearchCondition.isOnlySearchHostHearted() ? starPagePost.hostHeart.eq(true) : null; + } + + private BooleanExpression postAuthorEqHost(PostSearchCondition postSearchCondition) { + if (Objects.isNull(postSearchCondition)) { + return null; + } + return postSearchCondition.isOnlySearchHostWritten() ? + starPagePost.author.authorName.eq(starPage.information.host.starNickName) : null; + } +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostFeatureController.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostFeatureController.java new file mode 100644 index 0000000..870ea80 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostFeatureController.java @@ -0,0 +1,35 @@ +package com.neo.needeachother.post.presentation; + +import com.neo.needeachother.post.application.HostHeartService; +import com.neo.needeachother.post.application.LikePostService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/post") +public class PostFeatureController { + + private final HostHeartService hostHeartService; + private final LikePostService likePostService; + + @PutMapping("/{post_id}/heart") + public void demandGiveHostHeart(@PathVariable("post_id") Long postId, @RequestParam String email){ + hostHeartService.giveHostHeart(postId, email); + } + + @PutMapping("{post_id}/unheart") + public void demandRetrieveHostHeart(@PathVariable("post_id") Long postId, @RequestParam String email){ + hostHeartService.retrieveHostHeart(postId, email); + } + + @PutMapping("/{post_id}/like") + public void demandLikeThisPost(@PathVariable("post_id") Long postId, @RequestParam String email){ + likePostService.likeIt(postId, email); + } + + @PutMapping("/{post_id}/unlike") + public void demandCancelLikeThisPost(@PathVariable("post_id") Long postId, @RequestParam String email){ + likePostService.unLikeIt(postId, email); + } +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostStatusController.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostStatusController.java new file mode 100644 index 0000000..403e321 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostStatusController.java @@ -0,0 +1,25 @@ +package com.neo.needeachother.post.presentation; + +import com.neo.needeachother.post.application.DeletePostService; +import com.neo.needeachother.post.application.RestorePostService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/post") +public class PostStatusController { + + private final DeletePostService deletePostService; + private final RestorePostService restorePostService; + + @DeleteMapping("/{post_id}") + public void demandDeletePost(@PathVariable("post_id") Long postId, @RequestParam String email){ + deletePostService.deletePost(postId, email); + } + + @PutMapping("/{post_id}") + public void demandRestorePost(@PathVariable("post_id") Long postId, @RequestParam String email){ + restorePostService.restorePost(postId, email); + } +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostViewController.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostViewController.java new file mode 100644 index 0000000..9c5b999 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostViewController.java @@ -0,0 +1,65 @@ +package com.neo.needeachother.post.presentation; + +import com.neo.needeachother.post.application.PostByCategoryViewService; +import com.neo.needeachother.post.application.PostDetailViewService; +import com.neo.needeachother.post.application.dto.PostDetailDto; +import com.neo.needeachother.post.domain.dto.StarPagePostHeadlineDto; +import com.neo.needeachother.post.presentation.dto.GetPostPageByCategoryRequest; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/post") +public class PostViewController { + + private final PostByCategoryViewService postByCategoryViewService; + private final PostDetailViewService postDetailViewService; + + @GetMapping("/infinite") + public ResponseEntity> demandGetPostPageByCategoryWithInfiniteScroll( + @Valid @RequestBody GetPostPageByCategoryRequest postPageByCategoryRequest, + Pageable pageable) { + + Slice foundPostSlice = postByCategoryViewService.getPostPageByCategoryWithInfiniteScroll( + postPageByCategoryRequest.getCategoryId(), + postPageByCategoryRequest.getLastPostId(), + pageable, + postPageByCategoryRequest.isOrderByCreatedAt(), + postPageByCategoryRequest.isOrderByLikeCount(), + postPageByCategoryRequest.isOnlySearchHostWritten(), + postPageByCategoryRequest.isOnlySearchHostHearted() + ); + + return ResponseEntity.ok(foundPostSlice); + } + + @GetMapping("/page") + public ResponseEntity> demandGetPostPageByCategoryWithPaging( + @Valid @RequestBody GetPostPageByCategoryRequest postPageByCategoryRequest, + Pageable pageable) { + + Page foundPostPage = postByCategoryViewService.getPostPageByCategoryWithPaging( + postPageByCategoryRequest.getCategoryId(), + pageable, + postPageByCategoryRequest.isOrderByCreatedAt(), + postPageByCategoryRequest.isOrderByLikeCount(), + postPageByCategoryRequest.isOnlySearchHostWritten(), + postPageByCategoryRequest.isOnlySearchHostHearted() + ); + + return ResponseEntity.ok(foundPostPage); + } + + @GetMapping("/{post_id}") + public ResponseEntity demandGetPostDetail(@PathVariable("post_id") Long postId, @RequestParam String type){ + PostDetailDto foundPostDetail = postDetailViewService.getPostDetailView(type, postId); + return ResponseEntity.ok(foundPostDetail); + } + +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostWriteController.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostWriteController.java new file mode 100644 index 0000000..b459ed0 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/PostWriteController.java @@ -0,0 +1,71 @@ +package com.neo.needeachother.post.presentation; + +import com.neo.needeachother.post.application.WritePostService; +import com.neo.needeachother.post.domain.CommonPostParagraph; +import com.neo.needeachother.post.presentation.dto.WriteAlbumPostRequest; +import com.neo.needeachother.post.presentation.dto.WriteCommonPostRequest; +import com.neo.needeachother.post.presentation.dto.WriteGoldBalancePostRequest; +import com.neo.needeachother.post.presentation.dto.WriteVotePostRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/post") +public class PostWriteController { + + private final WritePostService writePostService; + + @PostMapping("/common") + public void demandWriteCommonPost(@RequestBody WriteCommonPostRequest writeCommonPostRequest){ + writePostService.writeCommonPost( + writeCommonPostRequest.getTitle(), + writeCommonPostRequest.getAuthorName(), + writeCommonPostRequest.getAuthorEmail(), + writeCommonPostRequest.getCategoryId(), + writeCommonPostRequest.getParagraphs() + ); + } + + @PostMapping("/album") + public void demandWriteAlbumPost(@RequestBody WriteAlbumPostRequest writeAlbumPostRequest){ + writePostService.writeAlbumPost( + writeAlbumPostRequest.getTitle(), + writeAlbumPostRequest.getAuthorName(), + writeAlbumPostRequest.getAuthorEmail(), + writeAlbumPostRequest.getCategoryId(), + writeAlbumPostRequest.getImagePath() + ); + } + + @PostMapping("/gold_balance") + public void demandWriteGoldBalancePost(@RequestBody WriteGoldBalancePostRequest writeGoldBalancePostRequest){ + writePostService.writeGoldBalancePost( + writeGoldBalancePostRequest.getTitle(), + writeGoldBalancePostRequest.getAuthorName(), + writeGoldBalancePostRequest.getAuthorEmail(), + writeGoldBalancePostRequest.getCategoryId(), + writeGoldBalancePostRequest.getQuestion(), + writeGoldBalancePostRequest.getLeftExample(), + writeGoldBalancePostRequest.getRightExample() + ); + } + + @PostMapping("/vote") + public void demandWriteVotePost(@RequestBody WriteVotePostRequest writeVotePostRequest){ + writePostService.writeVotePost( + writeVotePostRequest.getTitle(), + writeVotePostRequest.getAuthorName(), + writeVotePostRequest.getAuthorEmail(), + writeVotePostRequest.getCategoryId(), + writeVotePostRequest.getQuestion(), + writeVotePostRequest.getTimeToLive(), + writeVotePostRequest.getOptionTextList() + ); + } +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/CommonPostParagraphRequest.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/CommonPostParagraphRequest.java new file mode 100644 index 0000000..23af83f --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/CommonPostParagraphRequest.java @@ -0,0 +1,13 @@ +package com.neo.needeachother.post.presentation.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class CommonPostParagraphRequest { + private String paragraphType; + private String body; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/GetPostPageByCategoryRequest.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/GetPostPageByCategoryRequest.java new file mode 100644 index 0000000..72fc7ca --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/GetPostPageByCategoryRequest.java @@ -0,0 +1,16 @@ +package com.neo.needeachother.post.presentation.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; + +@Getter +@RequiredArgsConstructor +public class GetPostPageByCategoryRequest { + private String categoryId; + private Long lastPostId; + private boolean orderByCreatedAt; + private boolean orderByLikeCount; + private boolean onlySearchHostWritten; + private boolean onlySearchHostHearted; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteAlbumPostRequest.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteAlbumPostRequest.java new file mode 100644 index 0000000..3f75b9c --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteAlbumPostRequest.java @@ -0,0 +1,16 @@ +package com.neo.needeachother.post.presentation.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class WriteAlbumPostRequest { + private String title; + private String authorName; + private String authorEmail; + private String categoryId; + private String imagePath; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteCommonPostRequest.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteCommonPostRequest.java new file mode 100644 index 0000000..be2f40c --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteCommonPostRequest.java @@ -0,0 +1,18 @@ +package com.neo.needeachother.post.presentation.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +public class WriteCommonPostRequest { + private String title; + private String authorName; + private String authorEmail; + private String categoryId; + private List paragraphs; +} \ No newline at end of file diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteGoldBalancePostRequest.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteGoldBalancePostRequest.java new file mode 100644 index 0000000..240a106 --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteGoldBalancePostRequest.java @@ -0,0 +1,18 @@ +package com.neo.needeachother.post.presentation.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class WriteGoldBalancePostRequest { + private String title; + private String authorName; + private String authorEmail; + private String categoryId; + private String question; + private String leftExample; + private String rightExample; +} diff --git a/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteVotePostRequest.java b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteVotePostRequest.java new file mode 100644 index 0000000..336a86a --- /dev/null +++ b/needeachother/src/main/java/com/neo/needeachother/post/presentation/dto/WriteVotePostRequest.java @@ -0,0 +1,20 @@ +package com.neo.needeachother.post.presentation.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +public class WriteVotePostRequest { + private String title; + private String authorName; + private String authorEmail; + private String categoryId; + private String question; + private Integer timeToLive; + private List optionTextList; +} diff --git a/needeachother/src/test/java/com/neo/needeachother/category/infra/CategoryCustomRepositoryImplTest.java b/needeachother/src/test/java/com/neo/needeachother/category/infra/CategoryCustomRepositoryImplTest.java index 71107e6..2cda642 100644 --- a/needeachother/src/test/java/com/neo/needeachother/category/infra/CategoryCustomRepositoryImplTest.java +++ b/needeachother/src/test/java/com/neo/needeachother/category/infra/CategoryCustomRepositoryImplTest.java @@ -6,6 +6,7 @@ import com.neo.needeachother.category.domain.dto.CategoryViewDto; import com.neo.needeachother.category.domain.repository.CategoryRepository; import com.neo.needeachother.post.domain.*; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.starpage.domain.SNSLine; import com.neo.needeachother.starpage.domain.SNSType; import com.neo.needeachother.starpage.domain.StarPage; @@ -17,13 +18,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; -import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.Set; -import static org.junit.jupiter.api.Assertions.*; - @SpringBootTest class CategoryCustomRepositoryImplTest { diff --git a/needeachother/src/test/java/com/neo/needeachother/post/infra/PostRepositoryImplTest.java b/needeachother/src/test/java/com/neo/needeachother/post/infra/PostRepositoryImplTest.java new file mode 100644 index 0000000..443e15f --- /dev/null +++ b/needeachother/src/test/java/com/neo/needeachother/post/infra/PostRepositoryImplTest.java @@ -0,0 +1,159 @@ +package com.neo.needeachother.post.infra; + +import com.neo.needeachother.category.domain.Category; +import com.neo.needeachother.category.domain.CategoryId; +import com.neo.needeachother.category.domain.ContentRestriction; +import com.neo.needeachother.category.domain.repository.CategoryRepository; +import com.neo.needeachother.post.domain.*; +import com.neo.needeachother.post.domain.dto.PostSearchCondition; +import com.neo.needeachother.post.domain.dto.StarPagePostHeadlineDto; +import com.neo.needeachother.post.domain.repository.PostRepository; +import com.neo.needeachother.starpage.domain.SNSLine; +import com.neo.needeachother.starpage.domain.SNSType; +import com.neo.needeachother.starpage.domain.StarPage; +import com.neo.needeachother.starpage.domain.domainservice.CreateCategoryFromStarPageService; +import com.neo.needeachother.starpage.domain.domainservice.StarPageIdGenerateService; +import com.neo.needeachother.starpage.domain.repository.StarPageRepository; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.transaction.annotation.Transactional; +import static com.neo.needeachother.post.application.PostServiceHelper.*; + +import java.util.*; + + +@SpringBootTest +class PostRepositoryImplTest { + + @Autowired + private StarPageRepository starPageRepository; + + @Autowired + private CategoryRepository categoryRepository; + + @Autowired + private PostRepository postRepository; + + @Autowired + private StarPageIdGenerateService idGenerateService; + + @Autowired + private CreateCategoryFromStarPageService createCategoryFromStarPageService; + + @Test + @Transactional + public void testForSearchPostHeadlineByCategoryIdWithPaging() { + StarPage dummyStarPage1 = starPageRepository.save(StarPage.create(idGenerateService.getNextId(), "박보영", "boyoung@naver.com", Set.of("ACTOR"), + List.of(SNSLine.of(SNSType.YOUTUBE, "boyoung.youtube.com")), "보영")); + + Category category = categoryRepository.save(dummyStarPage1.createCommonTypeCategory(createCategoryFromStarPageService, "category1", ContentRestriction.of(false, false, false, 0))); + + List postList = new ArrayList<>(); + + for(int i = 0; i<100; i++){ + postList.add(new CommonPost(category.getCategoryId(), String.valueOf(i), Author.of("hihi", "aaa@naver.com"), PostStatus.OPEN, new ArrayList<>())); + } + postRepository.saveAll(postList); + + System.out.println(postRepository.findAll().size()); + + Page result = postRepository.searchPostHeadlineByCategoryIdWithPaging(category.getCategoryId(), + PostSearchCondition.builder() + .orderByCreatedAt(true) + .orderByLikeCount(false) + .onlySearchHostHearted(false) + .onlySearchHostWritten(false) + .build(), + PageRequest.of(0, 20)); + + Page result2 = postRepository.searchPostHeadlineByCategoryIdWithPaging(category.getCategoryId(), + PostSearchCondition.builder() + .orderByCreatedAt(true) + .orderByLikeCount(false) + .onlySearchHostHearted(false) + .onlySearchHostWritten(false) + .build(), + PageRequest.of(2, 20)); + + + System.out.println(result.getTotalElements() + " " + result.getTotalPages() + " " + result.getNumber() + " " + result.getNumberOfElements()); + System.out.println(result.getContent().stream().map(StarPagePostHeadlineDto::toString).toList()); + + System.out.println(result2.getTotalElements() + " " + result2.getTotalPages() + " " + result2.getNumber() + " " + result2.getNumberOfElements()); + System.out.println(result2.getContent().stream().map(StarPagePostHeadlineDto::toString).toList()); + } + + + @Test + @Transactional + public void testForSearchPostHeadlineByCategoryIdWithNoOffset() { + StarPage dummyStarPage1 = starPageRepository.save(StarPage.create(idGenerateService.getNextId(), "박보영", "boyoung@naver.com", Set.of("ACTOR"), + List.of(SNSLine.of(SNSType.YOUTUBE, "boyoung.youtube.com")), "보영")); + + Category category = categoryRepository.save(dummyStarPage1.createCommonTypeCategory(createCategoryFromStarPageService, "category1", ContentRestriction.of(false, false, false, 0))); + + List postList = new ArrayList<>(); + + for(int i = 0; i<100; i++){ + postList.add(new CommonPost(category.getCategoryId(), String.valueOf(i), Author.of("hihi", "aaa@naver.com"), PostStatus.OPEN, new ArrayList<>())); + } + postRepository.saveAll(postList); + + System.out.println(postRepository.findAll().size()); + + Slice result = postRepository.searchPostHeadlineByCategoryIdWithNoOffset(category.getCategoryId(), + PostSearchCondition.builder() + .orderByCreatedAt(true) + .orderByLikeCount(false) + .onlySearchHostHearted(false) + .onlySearchHostWritten(false) + .build(), + 3000L, + PageRequest.ofSize(20)); + + Long lastPostId = result.getContent().get(result.getSize() -1).getPostId(); + System.out.println(result.getSize() + " " + result.hasNext() + " " + result.getNumber() + " " + result.getNumberOfElements()); + System.out.println(result.getContent().stream().map(StarPagePostHeadlineDto::toString).toList()); + + Slice result2 = postRepository.searchPostHeadlineByCategoryIdWithNoOffset(category.getCategoryId(), + PostSearchCondition.builder() + .orderByCreatedAt(true) + .orderByLikeCount(false) + .onlySearchHostHearted(false) + .onlySearchHostWritten(false) + .build(), + lastPostId, + PageRequest.ofSize(20)); + + System.out.println(result2.getSize() + " " + result2.hasNext() + " " + result2.getNumber() + " " + result2.getNumberOfElements()); + System.out.println(result2.getContent().stream().map(StarPagePostHeadlineDto::toString).toList()); + } + + @Test + @Transactional + public void testForFindCommonPostById(){ + postRepository.findCommonPostById(1012L); + } + + @Test + @Transactional + public void testForFindAlbumPostById(){ + postRepository.findAlbumPostById(1012L); + } + + @Test + @Transactional + public void testForFindGoldBalancePostById(){ + postRepository.findGoldBalancePostById(1012L); + } + + @Test + @Transactional + public void testForFindVotePostById(){ + postRepository.findVotePostById(1012L); + } +} \ No newline at end of file diff --git a/needeachother/src/test/java/com/neo/needeachother/starpage/infra/StarPageRepositoryImplTest.java b/needeachother/src/test/java/com/neo/needeachother/starpage/infra/StarPageRepositoryImplTest.java index 237762c..494caa1 100644 --- a/needeachother/src/test/java/com/neo/needeachother/starpage/infra/StarPageRepositoryImplTest.java +++ b/needeachother/src/test/java/com/neo/needeachother/starpage/infra/StarPageRepositoryImplTest.java @@ -1,23 +1,18 @@ package com.neo.needeachother.starpage.infra; import com.neo.needeachother.category.domain.Category; -import com.neo.needeachother.category.domain.CategoryId; import com.neo.needeachother.category.domain.ContentRestriction; import com.neo.needeachother.category.domain.repository.CategoryRepository; import com.neo.needeachother.post.domain.*; +import com.neo.needeachother.post.domain.repository.PostRepository; import com.neo.needeachother.starpage.domain.SNSLine; import com.neo.needeachother.starpage.domain.SNSType; import com.neo.needeachother.starpage.domain.StarPage; -import com.neo.needeachother.starpage.domain.StarPageId; import com.neo.needeachother.starpage.domain.domainservice.CreateCategoryFromStarPageService; import com.neo.needeachother.starpage.domain.domainservice.StarPageIdGenerateService; import com.neo.needeachother.starpage.domain.dto.RepresentativeArticleHeadLine; import com.neo.needeachother.starpage.domain.dto.VotePostHeadLine; import com.neo.needeachother.starpage.domain.repository.StarPageRepository; -import jakarta.persistence.EntityManager; -import lombok.RequiredArgsConstructor; -import org.aspectj.lang.annotation.Before; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;