Skip to content

Commit

Permalink
✨ [feat] 전체 게시글 조회(미리보기) api 디폴트 정렬 기준 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
y2hscmtk committed Aug 3, 2024
1 parent 175fa9c commit 0257b10
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 2 deletions.
Binary file modified .gradle/8.8/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -239,10 +241,20 @@ public ResponseEntity<ApiResponse<?>> getMyArticles(String email, Pageable pagea
return ResponseEntity.ok().body(ApiResponse.onSuccess(result));
}

/**
* 전체 게시글 조회(미리보기)
*/
@Override
public ResponseEntity<?> getAllArticle(Pageable pageable) {
// 기본 정렬 기준 설정: createdAt 속성 기준으로 내림차순 정렬
Pageable defaultPageable = PageRequest.of(
pageable.getPageNumber(),
pageable.getPageSize(),
Sort.by(Sort.Direction.DESC, "createdAt")
);

// 1. pageable 객체를 바탕으로 전체 게시글 엔티티 조회
Page<Article> articlePage = articleRepository.findAll(pageable);
Page<Article> articlePage = articleRepository.findAll(defaultPageable);
int totalPages = articlePage.getTotalPages();
// 2. 반환 DTO 생성 및 반환
List<ArticlePreviewDto.AllArticlePreview> resultDtoList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public String[] permitAllPaths() {
"/login", "/join", "/oauth2/**", "/ci",
"/api/article/today-error", "/api/scream/**",
"/api/article/all", "/api/article/tag/**",
"/api/article/today-error"
"/api/article/today-error", "/api/article/recommend/**"
};
}
}

0 comments on commit 0257b10

Please sign in to comment.