feat: add limit/pagination to pitstats endpoint (#134) #158

Merged
cal merged 8 commits from issue/134-feat-add-limit-pagination-to-pitstats-endpoint into main 2026-03-24 12:11:00 +00:00
Collaborator

Closes #134

Adds optional limit query parameter (default 100, max 500) to GET /api/v2/pitstats.

Changes

  • app/routers_v2/pitstats.py: Added limit: Optional[int] = 100 parameter; applied all_stats.limit(max(0, min(limit, 500))) after all filters, before the CSV/JSON branch — both response paths honour the limit.

Notes

  • Consistent with the pattern used in notifications, scout_claims, rewards, scout_opportunities, batstats, events, and awards endpoints.
  • count in the JSON response reflects the limited count (pre-existing pattern across all paginated endpoints).
  • The ruff formatter auto-reformatted the file on commit (single→double quotes, import/arg reformatting) — cosmetic only, no logic changes beyond the limit feature.
Closes #134 Adds optional `limit` query parameter (default 100, max 500) to `GET /api/v2/pitstats`. ## Changes - `app/routers_v2/pitstats.py`: Added `limit: Optional[int] = 100` parameter; applied `all_stats.limit(max(0, min(limit, 500)))` after all filters, before the CSV/JSON branch — both response paths honour the limit. ## Notes - Consistent with the pattern used in notifications, scout_claims, rewards, scout_opportunities, batstats, events, and awards endpoints. - `count` in the JSON response reflects the limited count (pre-existing pattern across all paginated endpoints). - The ruff formatter auto-reformatted the file on commit (single→double quotes, import/arg reformatting) — cosmetic only, no logic changes beyond the limit feature.
Claude added 1 commit 2026-03-24 07:32:25 +00:00
Closes #134

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude added the
ai-reviewing
label 2026-03-24 07:45:47 +00:00
Claude reviewed 2026-03-24 07:46:41 +00:00
Claude left a comment
Author
Collaborator

AI Code Review

Files Reviewed

  • app/routers_v2/pitstats.py (modified)

Findings

Correctness

  • limit: Optional[int] = 100 added to get_pit_stats; capped via max(0, min(limit, 500)) — correct, guards negative values and upper bound.
  • .limit() applied after all filters (after gs filter), before the if csv: branch — both CSV and JSON response paths honour the limit.
  • Optional already imported at line 3 — no missing import.
  • Implementation is identical to the established pattern across all 7 prior paginated endpoints.

Security

  • No issues found. All query parameters are typed (int/bool); Peewee ORM prevents SQL injection. Auth unchanged on POST/DELETE endpoints.

Style & Conventions

  • Ruff auto-reformatting (single→double quotes, import/arg reformatting) is cosmetic only — consistent with prior pagination PRs.
  • No issues found beyond the minor note below.

Suggestions

  • MINOR: limit: Optional[int] = 100 vs limit: int = 100 — PR #157 (awards) used the more precise non-Optional form since None is never an intended value. Both work identically in practice (FastAPI rejects non-integer input with a 422), but int = 100 is more self-documenting. Not a blocker; flagging for consistency if the pattern gets standardised in a follow-up pass.
  • MINOR: count in the JSON response reflects the limited count, not the total matching rows — pre-existing pattern across all 8 paginated endpoints. Non-blocking; a follow-up issue to add a total field project-wide would address this cleanly.
  • MINOR: limit=0 returns an empty response even when records exist (lower bound of max(0, ...) permits it). Same pedantic edge case as all prior PRs. Non-blocking.

Verdict: COMMENT

Clean, correct implementation. Follows the established pagination pattern exactly. No blockers. Posting as COMMENT rather than APPROVED due to Gitea self-review restriction.


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `app/routers_v2/pitstats.py` (modified) ### Findings #### Correctness - `limit: Optional[int] = 100` added to `get_pit_stats`; capped via `max(0, min(limit, 500))` — correct, guards negative values and upper bound. - `.limit()` applied after all filters (after `gs` filter), before the `if csv:` branch — both CSV and JSON response paths honour the limit. ✅ - `Optional` already imported at line 3 — no missing import. ✅ - Implementation is identical to the established pattern across all 7 prior paginated endpoints. #### Security - No issues found. All query parameters are typed (int/bool); Peewee ORM prevents SQL injection. Auth unchanged on POST/DELETE endpoints. #### Style & Conventions - Ruff auto-reformatting (single→double quotes, import/arg reformatting) is cosmetic only — consistent with prior pagination PRs. - No issues found beyond the minor note below. #### Suggestions - **MINOR**: `limit: Optional[int] = 100` vs `limit: int = 100` — PR #157 (awards) used the more precise non-Optional form since `None` is never an intended value. Both work identically in practice (FastAPI rejects non-integer input with a 422), but `int = 100` is more self-documenting. Not a blocker; flagging for consistency if the pattern gets standardised in a follow-up pass. - **MINOR**: `count` in the JSON response reflects the limited count, not the total matching rows — pre-existing pattern across all 8 paginated endpoints. Non-blocking; a follow-up issue to add a `total` field project-wide would address this cleanly. - **MINOR**: `limit=0` returns an empty response even when records exist (lower bound of `max(0, ...)` permits it). Same pedantic edge case as all prior PRs. Non-blocking. ### Verdict: COMMENT Clean, correct implementation. Follows the established pagination pattern exactly. No blockers. Posting as COMMENT rather than APPROVED due to Gitea self-review restriction. --- *Automated review by Claude PR Reviewer*
Claude added
ai-reviewed
and removed
ai-reviewing
labels 2026-03-24 07:46:59 +00:00
cal approved these changes 2026-03-24 12:04:59 +00:00
cal left a comment
Owner

Reviewed by Claude PR reviewer — clean implementation, consistent with established pagination pattern. Approving.

Reviewed by Claude PR reviewer — clean implementation, consistent with established pagination pattern. Approving.
cal added 1 commit 2026-03-24 12:05:20 +00:00
cal added 1 commit 2026-03-24 12:06:04 +00:00
cal added 1 commit 2026-03-24 12:07:06 +00:00
cal added 1 commit 2026-03-24 12:07:52 +00:00
cal added 1 commit 2026-03-24 12:08:55 +00:00
cal added 1 commit 2026-03-24 12:09:46 +00:00
cal added 1 commit 2026-03-24 12:10:39 +00:00
cal merged commit f2ff85556a into main 2026-03-24 12:11:00 +00:00
cal deleted branch issue/134-feat-add-limit-pagination-to-pitstats-endpoint 2026-03-24 12:11:00 +00:00
Sign in to join this conversation.
No description provided.