Skip to content

Commit 620217e

Browse files
authored
Add pagination to the pools endpoint (#3985)
* remove pools
1 parent d0927eb commit 620217e

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

cg/server/endpoints/pools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from http import HTTPStatus
2+
23
from flask import Blueprint, abort, g, jsonify, request
34

45
from cg.server.endpoints.utils import before_request
5-
from cg.store.models import Customer, Pool
66
from cg.server.ext import db
7+
from cg.store.models import Customer, Pool
78

89
POOLS_BLUEPRINT = Blueprint("pools", __name__, url_prefix="/api/v1")
910
POOLS_BLUEPRINT.before_request(before_request)

cg/store/crud/read.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,20 @@ def get_cases_by_customers_action_and_case_search(
225225
offset: int = 0,
226226
) -> tuple[list[Case], int]:
227227
"""
228-
Retrieve a list of cases filtered by customers, action, and matching names or internal ids.
228+
Return cases by customers, action, and matching names or internal ids, plus the total
229+
number of cases matching the filter criteria. A limit and offset can be applied to the
230+
query for pagination purposes.
229231
230232
Args:
231233
customers (list[Customer] | None): A list of customer objects to filter cases by.
232234
action (str | None): The action string to filter cases by.
233235
case_search (str | None): The case search string to filter cases by.
234-
limit (int | None, default=30): The maximum number of cases to return.
235-
offset (int, default=0): The offset to start returning cases by.
236+
limit (int | None, default=50): The maximum number of cases to return.
237+
offset (int, default=0): The offset number of cases for the query.
236238
Returns:
237-
tuple[list[Case], int]: A list of filtered cases sorted by creation time and truncated
238-
by the limit parameter, and the total number of samples before truncation.
239+
list[Case]: A list of filtered cases sorted by creation time and truncated
240+
by the limit parameter.
241+
int: The total number of cases returned before truncation.
239242
"""
240243
filter_functions: list[Callable] = [
241244
CaseFilter.BY_CUSTOMER_ENTRY_IDS,
@@ -635,11 +638,11 @@ def get_samples_by_customers_and_pattern(
635638
Args:
636639
customers (list[Customer] | None): A list of customer objects to filter cases by.
637640
pattern (str | None): The sample internal id or name pattern to search for.
638-
limit (int | None, default=30): The maximum number of cases to return.
639-
offset (int, default=0): The offset to start returning cases by.
641+
limit (int | None, default=50): The maximum number of samples to return.
642+
offset (int, default=0): The offset number of samples for the query.
640643
Returns:
641-
tuple[list[Sample], int]: A list of filtered samples truncated by the limit parameter
642-
and the total number of samples before truncation.
644+
list[Sample]: A list of filtered samples truncated by the limit parameter.
645+
int: The total number of samples returned before truncation.
643646
"""
644647
samples: Query = self._get_query(table=Sample)
645648
filter_functions: list[SampleFilter] = []

tests/store/crud/read/test_read.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,6 @@ def test_get_pools_to_render_with(
10141014

10151015
# WHEN fetching pools with no customer or enquiry
10161016
pools: list[Pool] = store_with_multiple_pools_for_customer.get_pools_to_render()
1017-
10181017
# THEN two pools should be returned
10191018
assert len(pools) == 2
10201019

@@ -1040,6 +1039,7 @@ def test_get_pools_to_render_with_customer_and_name_enquiry(
10401039
):
10411040
"""Test that pools can be fetched from the store by customer id."""
10421041
# GIVEN a database with two pools
1042+
10431043
# WHEN fetching pools by customer id and name enquiry
10441044
pools: list[Pool] = store_with_multiple_pools_for_customer.get_pools_to_render(
10451045
customers=store_with_multiple_pools_for_customer.get_customers(), enquiry=pool_name_1
@@ -1057,7 +1057,6 @@ def test_get_pools_to_render_with_customer_and_order_enquiry(
10571057
# GIVEN a database with two pools
10581058

10591059
# WHEN fetching pools by customer id and order enquiry
1060-
10611060
pools: list[Pool] = store_with_multiple_pools_for_customer.get_pools_to_render(
10621061
customers=store_with_multiple_pools_for_customer.get_customers(), enquiry=pool_order_1
10631062
)

0 commit comments

Comments
 (0)