Skip to content

Commit

Permalink
[feat] #17 기본 게시글 조회 api service 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuKwanKon committed Jan 3, 2024
1 parent 25484b2 commit a02c906
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import org.gachon.checkmate.domain.post.entity.SortType;
import org.gachon.checkmate.domain.post.repository.PostQuerydslRepository;
import org.gachon.checkmate.global.error.exception.EntityNotFoundException;
import org.gachon.checkmate.global.utils.EnumValueUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
Expand All @@ -37,6 +35,17 @@ public class PostService {
private final CheckListRepository checkListRepository;
private final PostQuerydslRepository postQuerydslRepository;

public PostSearchResponseDto getAllPosts(Long userId, String type, Pageable pageable) {
CheckList checkList = getCheckList(userId);
SortType sortType = toEntityCode(SortType.class, type);
Page<PostSearchDto> postSearchList = getAllPostsResults(pageable);
List<PostSearchElementResponseDto> searchResults = createPostSearchResponseDto(postSearchList, checkList);
sortByTypeForSearchResults(searchResults, Objects.requireNonNull(sortType));
List<PostSearchElementResponseDto> pagingSearchResults
= convertPaging(searchResults, pageable.getOffset(), pageable.getPageSize());
return PostSearchResponseDto.of(pagingSearchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements());
}

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 @@ -100,6 +109,10 @@ private int getRemainDate(LocalDate endDate) {
return (int) endDate.until(LocalDate.now(), ChronoUnit.DAYS);
}

private Page<PostSearchDto> getAllPostsResults(Pageable pageable) {
return postQuerydslRepository.findAllPosts(pageable);
}

private Page<PostSearchDto> getKeySearchResults(ImportantKeyType importantKeyType, Pageable pageable) {
return postQuerydslRepository.searchKeyPost(importantKeyType, pageable);
}
Expand Down

0 comments on commit a02c906

Please sign in to comment.