Skip to content

Commit

Permalink
Add pagination to the pools endpoint (#3985)
Browse files Browse the repository at this point in the history
* remove pools
  • Loading branch information
diitaz93 authored Jan 30, 2025
1 parent d0927eb commit 620217e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cg/server/endpoints/pools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from http import HTTPStatus

from flask import Blueprint, abort, g, jsonify, request

from cg.server.endpoints.utils import before_request
from cg.store.models import Customer, Pool
from cg.server.ext import db
from cg.store.models import Customer, Pool

POOLS_BLUEPRINT = Blueprint("pools", __name__, url_prefix="/api/v1")
POOLS_BLUEPRINT.before_request(before_request)
Expand Down
21 changes: 12 additions & 9 deletions cg/store/crud/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,20 @@ def get_cases_by_customers_action_and_case_search(
offset: int = 0,
) -> tuple[list[Case], int]:
"""
Retrieve a list of cases filtered by customers, action, and matching names or internal ids.
Return cases by customers, action, and matching names or internal ids, plus the total
number of cases matching the filter criteria. A limit and offset can be applied to the
query for pagination purposes.
Args:
customers (list[Customer] | None): A list of customer objects to filter cases by.
action (str | None): The action string to filter cases by.
case_search (str | None): The case search string to filter cases by.
limit (int | None, default=30): The maximum number of cases to return.
offset (int, default=0): The offset to start returning cases by.
limit (int | None, default=50): The maximum number of cases to return.
offset (int, default=0): The offset number of cases for the query.
Returns:
tuple[list[Case], int]: A list of filtered cases sorted by creation time and truncated
by the limit parameter, and the total number of samples before truncation.
list[Case]: A list of filtered cases sorted by creation time and truncated
by the limit parameter.
int: The total number of cases returned before truncation.
"""
filter_functions: list[Callable] = [
CaseFilter.BY_CUSTOMER_ENTRY_IDS,
Expand Down Expand Up @@ -635,11 +638,11 @@ def get_samples_by_customers_and_pattern(
Args:
customers (list[Customer] | None): A list of customer objects to filter cases by.
pattern (str | None): The sample internal id or name pattern to search for.
limit (int | None, default=30): The maximum number of cases to return.
offset (int, default=0): The offset to start returning cases by.
limit (int | None, default=50): The maximum number of samples to return.
offset (int, default=0): The offset number of samples for the query.
Returns:
tuple[list[Sample], int]: A list of filtered samples truncated by the limit parameter
and the total number of samples before truncation.
list[Sample]: A list of filtered samples truncated by the limit parameter.
int: The total number of samples returned before truncation.
"""
samples: Query = self._get_query(table=Sample)
filter_functions: list[SampleFilter] = []
Expand Down
3 changes: 1 addition & 2 deletions tests/store/crud/read/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,6 @@ def test_get_pools_to_render_with(

# WHEN fetching pools with no customer or enquiry
pools: list[Pool] = store_with_multiple_pools_for_customer.get_pools_to_render()

# THEN two pools should be returned
assert len(pools) == 2

Expand All @@ -1040,6 +1039,7 @@ def test_get_pools_to_render_with_customer_and_name_enquiry(
):
"""Test that pools can be fetched from the store by customer id."""
# GIVEN a database with two pools

# WHEN fetching pools by customer id and name enquiry
pools: list[Pool] = store_with_multiple_pools_for_customer.get_pools_to_render(
customers=store_with_multiple_pools_for_customer.get_customers(), enquiry=pool_name_1
Expand All @@ -1057,7 +1057,6 @@ def test_get_pools_to_render_with_customer_and_order_enquiry(
# GIVEN a database with two pools

# WHEN fetching pools by customer id and order enquiry

pools: list[Pool] = store_with_multiple_pools_for_customer.get_pools_to_render(
customers=store_with_multiple_pools_for_customer.get_customers(), enquiry=pool_order_1
)
Expand Down

0 comments on commit 620217e

Please sign in to comment.