diff --git a/src/main/java/com/example/globalTimes_be/domain/article/repository/ArticleRepository.java b/src/main/java/com/example/globalTimes_be/domain/article/repository/ArticleRepository.java index 0e20855..152297d 100644 --- a/src/main/java/com/example/globalTimes_be/domain/article/repository/ArticleRepository.java +++ b/src/main/java/com/example/globalTimes_be/domain/article/repository/ArticleRepository.java @@ -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 { @@ -16,4 +18,7 @@ public interface ArticleRepository extends JpaRepository { // 조회수 순 ( 랜딩페이지 Hot News 기반 ) Page
findAllByOrderByViewCountDesc(Pageable pageable); + + // 특정 id를 제외한 최신기사 20개 조회 + List
findTop20ByIdNotOrderByPublishedAtDesc(Long id); } diff --git a/src/main/java/com/example/globalTimes_be/domain/news/service/NewsService.java b/src/main/java/com/example/globalTimes_be/domain/news/service/NewsService.java index 5d20183..ad5658e 100644 --- a/src/main/java/com/example/globalTimes_be/domain/news/service/NewsService.java +++ b/src/main/java/com/example/globalTimes_be/domain/news/service/NewsService.java @@ -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; @@ -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
articleList = articleRepository.findAllByOrderByPublishedAtDesc(pageable).getContent(); + List
articleList = articleRepository.findTop20ByIdNotOrderByPublishedAtDesc(id); //최신 뉴스 정보를 DTO에 넣음 List recentNewsDTOList = articleList.stream()