Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ArticleRepository extends JpaRepository<Article, Long> {

Expand All @@ -16,4 +18,7 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {

// 조회수 순 ( 랜딩페이지 Hot News 기반 )
Page<Article> findAllByOrderByViewCountDesc(Pageable pageable);

// 특정 id를 제외한 최신기사 20개 조회
List<Article> findTop20ByIdNotOrderByPublishedAtDesc(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -49,10 +47,10 @@ public NewsResDTO getNewsDetail(Long id) {
.build();

//0번째 페이지, 한 페이지에 20개
Pageable pageable = PageRequest.of(0, 20);
//Pageable pageable = PageRequest.of(0, 20);

//최신 뉴스 정보를 20개 가져옴
List<Article> articleList = articleRepository.findAllByOrderByPublishedAtDesc(pageable).getContent();
List<Article> articleList = articleRepository.findTop20ByIdNotOrderByPublishedAtDesc(id);

//최신 뉴스 정보를 DTO에 넣음
List<RecentNewsDTO> recentNewsDTOList = articleList.stream()
Expand Down