From fd4c24a1d3d6c66c267f787ff9a85ebf51a0dee6 Mon Sep 17 00:00:00 2001 From: gitjiho <jiho99322@gmail.com> Date: Wed, 27 Nov 2024 23:43:09 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20top=2010=EB=A7=8C=20=EB=9C=A8=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ott/history/repository/ContentLikeRepository.java | 3 ++- .../ott/history/repository/WatchHistoryRepository.java | 3 ++- .../com/software/ott/history/service/ContentLikeService.java | 5 ++++- .../software/ott/history/service/WatchHistoryService.java | 5 ++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/software/ott/history/repository/ContentLikeRepository.java b/src/main/java/com/software/ott/history/repository/ContentLikeRepository.java index eb09529..c4a7175 100644 --- a/src/main/java/com/software/ott/history/repository/ContentLikeRepository.java +++ b/src/main/java/com/software/ott/history/repository/ContentLikeRepository.java @@ -1,6 +1,7 @@ package com.software.ott.history.repository; import com.software.ott.history.entity.ContentLike; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -18,5 +19,5 @@ public interface ContentLikeRepository extends JpaRepository<ContentLike, Long> "WHERE cl.liked = true " + "GROUP BY cl.content " + "ORDER BY likeCount DESC") - List<Object[]> findTop10MostLikedContents(); + List<Object[]> findTopMostLikedContents(Pageable pageable); } diff --git a/src/main/java/com/software/ott/history/repository/WatchHistoryRepository.java b/src/main/java/com/software/ott/history/repository/WatchHistoryRepository.java index 61e23a2..9e7bd84 100644 --- a/src/main/java/com/software/ott/history/repository/WatchHistoryRepository.java +++ b/src/main/java/com/software/ott/history/repository/WatchHistoryRepository.java @@ -1,6 +1,7 @@ package com.software.ott.history.repository; import com.software.ott.history.entity.WatchHistory; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -17,5 +18,5 @@ public interface WatchHistoryRepository extends JpaRepository<WatchHistory, Long @Query("SELECT wh.content, COUNT(wh) AS watchCount FROM WatchHistory wh " + "GROUP BY wh.content " + "ORDER BY watchCount DESC") - List<Object[]> findTop10MostWatchedContents(); + List<Object[]> findTop10MostWatchedContents(Pageable pageable); } diff --git a/src/main/java/com/software/ott/history/service/ContentLikeService.java b/src/main/java/com/software/ott/history/service/ContentLikeService.java index 1422600..7562069 100644 --- a/src/main/java/com/software/ott/history/service/ContentLikeService.java +++ b/src/main/java/com/software/ott/history/service/ContentLikeService.java @@ -11,6 +11,8 @@ import com.software.ott.member.entity.Member; import com.software.ott.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -59,7 +61,8 @@ public List<ContentLikeResponse> readAllLikeContentsByMember(Long memberId, bool @Transactional public List<TopContentLikeResponse> getTop10MostLikedContents() { - List<Object[]> topContents = contentLikeRepository.findTop10MostLikedContents(); + Pageable top10 = PageRequest.of(0, 10); + List<Object[]> topContents = contentLikeRepository.findTopMostLikedContents(top10); return topContents.stream() .map(result -> { diff --git a/src/main/java/com/software/ott/history/service/WatchHistoryService.java b/src/main/java/com/software/ott/history/service/WatchHistoryService.java index c1af96b..2a2fe2e 100644 --- a/src/main/java/com/software/ott/history/service/WatchHistoryService.java +++ b/src/main/java/com/software/ott/history/service/WatchHistoryService.java @@ -11,6 +11,8 @@ import com.software.ott.member.entity.Member; import com.software.ott.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -68,7 +70,8 @@ public void deleteWatchHistory(Long memberId, Long contentId) { @Transactional public List<TopWatchHistoryResponse> getTop10WatchedContents() { - List<Object[]> topContents = watchHistoryRepository.findTop10MostWatchedContents(); + Pageable top10 = PageRequest.of(0, 10); + List<Object[]> topContents = watchHistoryRepository.findTop10MostWatchedContents(top10); return topContents.stream() .map(result -> {