Skip to content

Conversation

@MatthewBarghout
Copy link
Collaborator

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

@github-actions
Copy link

Test Results Summary

302 tests  ±0   302 ✅ ±0   11s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit b10ba3f. ± Comparison against base commit c972c7c.

@MatthewBarghout MatthewBarghout changed the title fixes BackendFilter/Sort Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend FIlter/Sort

2 participants