feat: add limit/pagination to pitchingcardratings endpoint (#136) #161

Merged
cal merged 8 commits from issue/136-feat-add-limit-pagination-to-pitchingcardratings-e into main 2026-03-24 12:08:45 +00:00
Collaborator

Closes #136

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

Changes

  • app/routers_v2/pitchingcardratings.py: Added limit: int = 100 parameter to get_card_ratings(); limit capped via max(0, min(limit, 500)) applied after all filters and before the CSV/JSON branch — both response paths honour the limit.

Other observations

  • The ruff pre-commit hook also caught 4 pre-existing F541 violations (f-strings without placeholders) in get_scouting_dfs() and post_calc_scouting()/post_calc_basic() — these were auto-fixed to unblock the commit. Non-functional.
  • count in the JSON response reflects the limited count (not total matching rows) — consistent with the pre-existing pattern across all other paginated endpoints in this repo.
Closes #136 Adds optional `limit: int` query parameter (default 100, max 500) to `GET /api/v2/pitchingcardratings`. ## Changes - `app/routers_v2/pitchingcardratings.py`: Added `limit: int = 100` parameter to `get_card_ratings()`; limit capped via `max(0, min(limit, 500))` applied after all filters and before the CSV/JSON branch — both response paths honour the limit. ## Other observations - The ruff pre-commit hook also caught 4 pre-existing F541 violations (f-strings without placeholders) in `get_scouting_dfs()` and `post_calc_scouting()`/`post_calc_basic()` — these were auto-fixed to unblock the commit. Non-functional. - `count` in the JSON response reflects the limited count (not total matching rows) — consistent with the pre-existing pattern across all other paginated endpoints in this repo.
Claude added 1 commit 2026-03-24 09:03:07 +00:00
Closes #136

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

AI Code Review

Files Reviewed

  • app/routers_v2/pitchingcardratings.py (modified)

Findings

Correctness

  • limit: int = 100 added to get_card_ratings() function signature — matches PR description exactly.
  • all_ratings = all_ratings.limit(max(0, min(limit, 500))) applied after all three filter branches (pitchingcard_id, vs_hand, cardset_id) and before the if csv: branch — both CSV and JSON response paths honour the limit.
  • max(0, min(limit, 500)) correctly guards against negative values and enforces the 500 upper bound.
  • No new imports required (int used directly, no Optional needed).

Security

  • No issues. limit is an integer parameter validated by FastAPI type coercion before it reaches Peewee. .limit() with an integer is safe from injection.

Style & Conventions

  • MINOR: limit: int = 100 (not Optional[int]) — minor inconsistency with most other paginated endpoints in this repo that use Optional[int]. Both are functionally identical in FastAPI. Non-blocking; follows the same pattern as PR #157 (awards) and PR #159 (battingcardratings).
  • MINOR: count in the JSON response reflects the limited count, not total matching rows — consistent with the pre-existing pattern across all prior paginated endpoints. Non-blocking.
  • MINOR: limit=0 passes max(0, min(0, 500)) = 0 → Peewee LIMIT 0 → empty result. Same pedantic edge case as all prior pagination PRs. Non-blocking.
  • F541 ruff fixes (4 f-strings without placeholders → plain strings in get_scouting_dfs(), post_calc_scouting(), post_calc_basic()) are non-functional cleanup. Correct.

Suggestions

  • No blocking suggestions. This is the 11th endpoint to receive pagination and the implementation is clean and consistent.

Verdict: COMMENT

Implementation is correct and follows the established pagination pattern. 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/pitchingcardratings.py` (modified) ### Findings #### Correctness - `limit: int = 100` added to `get_card_ratings()` function signature — matches PR description exactly. - `all_ratings = all_ratings.limit(max(0, min(limit, 500)))` applied after all three filter branches (`pitchingcard_id`, `vs_hand`, `cardset_id`) and before the `if csv:` branch — both CSV and JSON response paths honour the limit. ✅ - `max(0, min(limit, 500))` correctly guards against negative values and enforces the 500 upper bound. ✅ - No new imports required (`int` used directly, no `Optional` needed). ✅ #### Security - No issues. `limit` is an integer parameter validated by FastAPI type coercion before it reaches Peewee. `.limit()` with an integer is safe from injection. #### Style & Conventions - **MINOR**: `limit: int = 100` (not `Optional[int]`) — minor inconsistency with most other paginated endpoints in this repo that use `Optional[int]`. Both are functionally identical in FastAPI. Non-blocking; follows the same pattern as PR #157 (awards) and PR #159 (battingcardratings). - **MINOR**: `count` in the JSON response reflects the limited count, not total matching rows — consistent with the pre-existing pattern across all prior paginated endpoints. Non-blocking. - **MINOR**: `limit=0` passes `max(0, min(0, 500))` = 0 → Peewee `LIMIT 0` → empty result. Same pedantic edge case as all prior pagination PRs. Non-blocking. - F541 ruff fixes (4 f-strings without placeholders → plain strings in `get_scouting_dfs()`, `post_calc_scouting()`, `post_calc_basic()`) are non-functional cleanup. Correct. #### Suggestions - No blocking suggestions. This is the 11th endpoint to receive pagination and the implementation is clean and consistent. ### Verdict: COMMENT Implementation is correct and follows the established pagination pattern. 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 09:17:16 +00:00
cal approved these changes 2026-03-24 12:04:43 +00:00
cal left a comment
Owner

LGTM — clean pagination implementation consistent with the established pattern across other endpoints. Ruff fixes are a bonus.

LGTM — clean pagination implementation consistent with the established pattern across other endpoints. Ruff fixes are a bonus.
cal added 1 commit 2026-03-24 12:05:04 +00:00
cal added 1 commit 2026-03-24 12:06:15 +00:00
cal added 1 commit 2026-03-24 12:06:52 +00:00
cal added 1 commit 2026-03-24 12:07:21 +00:00
cal added 1 commit 2026-03-24 12:08:01 +00:00
cal added 1 commit 2026-03-24 12:08:16 +00:00
cal added 1 commit 2026-03-24 12:08:32 +00:00
cal merged commit c1a8808cd3 into main 2026-03-24 12:08:45 +00:00
cal deleted branch issue/136-feat-add-limit-pagination-to-pitchingcardratings-e 2026-03-24 12:08:46 +00:00
Sign in to join this conversation.
No description provided.