Skip to content

refactor: wire accounts/fraud routers to the shared pagination envelope - #1093

Merged
gelluisaac merged 1 commit into
Traqora:mainfrom
iamthebestofcourse:feat/pagination-envelope-standard
Oct 27, 2026
Merged

gelluisaac merged 1 commit into
Traqora:mainfrom
iamthebestofcourse:feat/pagination-envelope-standard

Conversation

@iamthebestofcourse

Copy link
Copy Markdown
Contributor

Summary

astroml/db/session.py already defines PageParams/Page/paginate_offset as the standard pagination envelope (issue #948), but the two routers that envelope was designed for, astroml/api/routers/accounts.py and astroml/api/routers/fraud.py, still hand-rolled the same (items, total, page, page_size) shape and the same offset = (page - 1) * page_size math themselves, duplicating what the shared helper already does.

closes #953

Changes

  • list_accounts, get_account_transactions (accounts.py), and list_fraud_alerts (fraud.py) now take page_params: PageParams = Depends() instead of separate page/page_size query params, and build their response with paginate_offset(items, total, page_params) instead of manually computing offset and constructing the response dict by hand.
  • No change to the public query-parameter contract: PageParams already validates page/page_size identically (page >= 1, 1 <= page_size <= 100, defaults 1/20) to the Query(...) declarations it replaces.
  • Response shape is unchanged (items, total, page, page_size).

Test plan

  • Added to tests/test_pagination_envelope.py: test_paginated_endpoints_take_page_params_as_a_dependency (all three endpoints take PageParams via Depends) and test_router_modules_import_the_shared_envelope (asserts paginate_offset is used and the old (page - 1) * page_size formula is gone from both router modules). 34/34 tests in that file pass.
  • black --check, ruff check: clean on both touched router files and the test file.
  • mypy: identical pre-existing errors on both router files before and after this change (verified via git stash + rerun), no new errors introduced.
  • Full end-to-end HTTP test of these endpoints (tests/performance/test_api_endpoints.py) requires the full requirements-api.txt dependency tree (jose, strawberry-graphql, etc.) which isn't set up in this environment; not run here, but nothing in this change touches auth, GraphQL, or request/response wire format, only the internal pagination computation.

list_accounts, get_account_transactions, and list_fraud_alerts each
hand-rolled the same (items, total, page, page_size) response shape and
offset = (page - 1) * page_size math that PageParams/Page/paginate_offset
in astroml.db.session (Traqora#948) already standardize. Switch all three to
the shared envelope instead of reimplementing it.
@gelluisaac
gelluisaac merged commit 9c02232 into Traqora:main Oct 27, 2026
13 of 36 checks passed
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.

[enhancement] Pagination envelope standard

2 participants