Skip to content

Commit

Permalink
REFACTORING : PAGING LIMIT 10
Browse files Browse the repository at this point in the history
  • Loading branch information
JuseungL committed Aug 4, 2024
1 parent 15244e3 commit d057324
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,10 +15,11 @@ public interface PurchaseRecordRepository extends JpaRepository<PurchaseRecord,
List<PurchaseRecord> 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<ProductType> findRecentProductTypesByMemberId(@Param("memberId") Long memberId);
List<ProductType> findRecentProductTypesByMemberId(@Param("memberId") Long memberId, Pageable pageable);


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

Expand All @@ -33,7 +35,8 @@ public List<PurchaseRecordGetResponseDto> getAllPurchaseRecords(Long memberId) {
}

public List<String> getPurchaseCount(Long memberId) {
List<ProductType> productTypes = purchaseRecordRepository.findRecentProductTypesByMemberId(memberId);
Pageable pageable = PageRequest.of(0, 10); // Page 0, Size 10
List<ProductType> productTypes = purchaseRecordRepository.findRecentProductTypesByMemberId(memberId, pageable);
return productTypes.stream()
.map(productType -> String.valueOf(productType))
.collect(Collectors.toList());
Expand Down

0 comments on commit d057324

Please sign in to comment.