diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index 34c1054..a15ee79 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -1,11 +1,14 @@ package org.gachon.checkmate.domain.post.service; import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.checkList.dto.response.CheckListResponseDto; import org.gachon.checkmate.domain.checkList.entity.CheckList; import org.gachon.checkmate.domain.checkList.entity.PostCheckList; import org.gachon.checkmate.domain.checkList.repository.CheckListRepository; +import org.gachon.checkmate.domain.post.dto.response.PostDetailResponseDto; import org.gachon.checkmate.domain.post.dto.response.PostSearchElementResponseDto; import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto; +import org.gachon.checkmate.domain.post.dto.support.PostDetailDto; import org.gachon.checkmate.domain.post.dto.support.PostSearchDto; import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.entity.SortType; @@ -24,6 +27,7 @@ import java.util.stream.Collectors; import static org.gachon.checkmate.global.error.ErrorCode.CHECK_LIST_NOT_FOUND; +import static org.gachon.checkmate.global.error.ErrorCode.POST_NOT_FOUND; import static org.gachon.checkmate.global.utils.EnumValueUtils.toEntityCode; import static org.gachon.checkmate.global.utils.PagingUtils.convertPaging; @@ -46,6 +50,12 @@ public PostSearchResponseDto getAllPosts(Long userId, String type, Pageable page return PostSearchResponseDto.of(pagingSearchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements()); } + public PostDetailResponseDto getPostDetails(Long postId) { + PostDetailDto postDetailDto = getPostDetailDto(postId); + CheckListResponseDto checkListResponseDto = createCheckListResponseDto(postDetailDto.postCheckList()); + return PostDetailResponseDto.of(postDetailDto, checkListResponseDto); + } + public PostSearchResponseDto searchKeyWordPost(Long userId, String key, String type, Pageable pageable) { CheckList checkList = getCheckList(userId); SortType sortType = toEntityCode(SortType.class, type); @@ -75,6 +85,17 @@ private List createPostSearchResponseDto(Page posts, SortType sortType) { if (sortType.equals(SortType.ACCURACY)) sortByAccuracyType(posts); @@ -125,4 +146,9 @@ private CheckList getCheckList(Long userId) { return checkListRepository.findByUserId(userId) .orElseThrow(() -> new EntityNotFoundException(CHECK_LIST_NOT_FOUND)); } + + private PostDetailDto getPostDetailDto(Long postId) { + return postQuerydslRepository.findPostDetail(postId) + .orElseThrow(() -> new EntityNotFoundException(POST_NOT_FOUND)); + } }