Skip to content

Commit

Permalink
[feat] #20 게시글 상세 조회 service 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuKwanKon committed Jan 4, 2024
1 parent 422a34c commit 4387367
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -75,6 +85,17 @@ private List<PostSearchElementResponseDto> createPostSearchResponseDto(Page<Post
.collect(Collectors.toList());
}

private CheckListResponseDto createCheckListResponseDto(PostCheckList postCheckList) {
return CheckListResponseDto.of(
postCheckList.getCleanType().getDesc(),
postCheckList.getDrinkType().getDesc(),
postCheckList.getHomeType().getDesc(),
postCheckList.getLifePatterType().getDesc(),
postCheckList.getNoiseType().getDesc(),
postCheckList.getSleepType().getDesc()
);
}

private void sortByTypeForSearchResults(List<PostSearchElementResponseDto> posts, SortType sortType) {
if (sortType.equals(SortType.ACCURACY))
sortByAccuracyType(posts);
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 4387367

Please sign in to comment.