Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
High-level motivation for making the changes
Added server-side pagination, sorting, and filtering to the /api/parties/ endpoint to improve performance and scalability as the database grows. Previously, all filtering and sorting happened client-side, which doesn't scale beyond a few hundred records.
Changes:
Core utilities (backend/src/core/query_utils.py):
Added reusable pagination, sorting, and filtering utilities for SQLAlchemy queries
Implemented PaginationParams, SortParam, FilterParam models with Pydantic validation
Created apply_query_params() to combine filters, sorting, and pagination with security whitelisting
Added get_total_count() to efficiently count filtered results before pagination
Party service (backend/src/modules/party/party_service.py):
Added get_parties_paginated() method with support for:
Optional pagination (page_number, page_size)
Sorting by party_datetime, location_id, contact_one_id, or id
Filtering by location_id and/or contact_one_id
Whitelisted allowed sort/filter fields for security
Party router (backend/src/modules/party/party_router.py):
Updated list_parties endpoint to accept query parameters for pagination, sorting, and filtering
All features are opt-in with sensible defaults (backward compatible)
Tests (backend/test/modules/party/test_party_list_features.py):
Added comprehensive test suite with 22 tests covering:
Pagination edge cases (empty DB, exact pages, remainders, beyond last page)
Sorting (ascending/descending by different fields)
Filtering (single and multiple filters)
Combined features (filter + sort + paginate together)
Bug fixes:
Fixed PartyTestUtils.next_dict() to avoid mutating the overrides dict (was causing test failures)
Fixed get_total_count() to properly count rows instead of columns
Closes #161