Skip to content

Commit

Permalink
fix: top 10만 뜨도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
GitJIHO committed Nov 27, 2024
1 parent 9e7eabf commit fd4c24a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 -> {
Expand Down

0 comments on commit fd4c24a

Please sign in to comment.