From d0573240ad14be180de0f3a403b8b6ce546d6387 Mon Sep 17 00:00:00 2001 From: JuseungL <121665437+JuseungL@users.noreply.github.com> Date: Mon, 5 Aug 2024 05:29:09 +0900 Subject: [PATCH] REFACTORING : PAGING LIMIT 10 --- .../api/purchase/repository/PurchaseRecordRepository.java | 8 +++++--- .../api/purchase/service/PurchaseRecordQueryService.java | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/lion6/DrinkGuide/api/purchase/repository/PurchaseRecordRepository.java b/src/main/java/lion6/DrinkGuide/api/purchase/repository/PurchaseRecordRepository.java index 12b84c6..7ffb23a 100644 --- a/src/main/java/lion6/DrinkGuide/api/purchase/repository/PurchaseRecordRepository.java +++ b/src/main/java/lion6/DrinkGuide/api/purchase/repository/PurchaseRecordRepository.java @@ -3,6 +3,7 @@ import lion6.DrinkGuide.api.member.domain.Member; import lion6.DrinkGuide.api.purchase.domain.ProductType; import lion6.DrinkGuide.api.purchase.domain.PurchaseRecord; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -14,10 +15,11 @@ public interface PurchaseRecordRepository extends JpaRepository findAllByMemberOrderByCreatedDate(Member member); @Query(value = "SELECT pr.productType FROM PurchaseRecord pr " + - "WHERE MONTH(pr.createdDate) = MONTH(NOW()) " + // 필드 이름 확인 + "WHERE MONTH(pr.createdDate) = MONTH(NOW()) " + "AND YEAR(pr.createdDate) = YEAR(NOW()) " + - "AND pr.member.id = :memberId " + // member_id 조건 수정 + "AND pr.member.id = :memberId " + "ORDER BY pr.createdDate DESC") - List findRecentProductTypesByMemberId(@Param("memberId") Long memberId); + List findRecentProductTypesByMemberId(@Param("memberId") Long memberId, Pageable pageable); + } diff --git a/src/main/java/lion6/DrinkGuide/api/purchase/service/PurchaseRecordQueryService.java b/src/main/java/lion6/DrinkGuide/api/purchase/service/PurchaseRecordQueryService.java index f5518ca..829fee6 100644 --- a/src/main/java/lion6/DrinkGuide/api/purchase/service/PurchaseRecordQueryService.java +++ b/src/main/java/lion6/DrinkGuide/api/purchase/service/PurchaseRecordQueryService.java @@ -10,6 +10,8 @@ import lion6.DrinkGuide.api.purchase.dto.response.PurchaseRecordGetResponseDto; import lion6.DrinkGuide.api.purchase.repository.PurchaseRecordRepository; 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; @@ -33,7 +35,8 @@ public List getAllPurchaseRecords(Long memberId) { } public List getPurchaseCount(Long memberId) { - List productTypes = purchaseRecordRepository.findRecentProductTypesByMemberId(memberId); + Pageable pageable = PageRequest.of(0, 10); // Page 0, Size 10 + List productTypes = purchaseRecordRepository.findRecentProductTypesByMemberId(memberId, pageable); return productTypes.stream() .map(productType -> String.valueOf(productType)) .collect(Collectors.toList());