Pull Request #5128
Add pagination to invoice list endpoint
Prevents unbounded invoice result sets from timing out for customers with large billing histories.
Ready to merge
repository/InvoiceRepository.java+12 additions
Viewed1
@Repository
2
public interface InvoiceRepository extends JpaRepository<Invoice, Long> {
3
4
@Query(
5
value = """
6
SELECT *
7
FROM invoices
8
WHERE customer_id = :customerId
9
""",
10
nativeQuery = true
11
)
12
List<Invoice> findInvoices(
13
@Param("customerId") String customerId
14
);
15
16
+ @Query(
17
+ value = """
18
+ SELECT *
19
+ FROM invoices
20
+ WHERE customer_id = :customerId
21
+ LIMIT :pageSize
22
+ OFFSET :offset
23
+ """,
24
+ nativeQuery = true
25
+ )
26
+ List<Invoice> findPaginatedInvoices(
27
+ @Param("customerId") String customerId,
28
+ @Param("offset") int offset,
29
+ @Param("pageSize") int pageSize
30
+ );
32
Optional<Invoice> findByIdAndCustomerId(Long id, String customerId);
33
}