feat: add limit/pagination to mlbplayers endpoint (#141) #162
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#162
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/141-feat-add-limit-pagination-to-mlbplayers-endpoint"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #141
Adds
limit: int = 100query parameter toGET /api/v2/mlbplayers. The limit is capped viamax(0, min(limit, 500))to guard against negative values and enforce the 500-row upper bound. Applied after all filters and before theif csv:branch so both CSV and JSON paths honour the limit.Files changed:
app/routers_v2/mlbplayers.pyOther observations:
f"POST /mlbplayers/one - dupes found:"— f-string without placeholder) was blocking the pre-commit hook; fixed as a required side-effect of committing.AI Code Review
Files Reviewed
app/routers_v2/mlbplayers.py(modified)Findings
Correctness
limit: int = 100added toGET /api/v2/mlbplayers— correct form, matching the pattern established in PRs #157, #159, #161.all_players = all_players.limit(max(0, min(limit, 500)))placed after all eight filter branches (full_name, first_name, last_name, key_fangraphs, key_bbref, key_retro, key_mlbam, offense_col) and before theif csv:branch — both CSV and JSON paths honour the limit. ✅max(0, ...)) and upper-bound cap (min(..., 500)) are correct.f"POST /mlbplayers/one - dupes found:"→ plain string — correct, no placeholder was present.Security
Style & Conventions
limit: int(notOptional[int]) — cosmetic inconsistency with some earlier paginated endpoints (e.g., #154, #155, #156, #158), but consistent with the three most recent ones (#157, #159, #161). Both are functionally identical in FastAPI; non-blocking.countin the JSON response reflects the limited count, not the total matching rows. This is the pre-existing pattern across 11 of 12 paginated endpoints (only gauntletruns in PR #160 diverges). Non-blocking, but a follow-up issue to add atotalfield project-wide would benefit pagination callers.limit=0returns an empty response even when records exist (max(0, 0) = 0). Same pedantic edge case present in all prior pagination PRs; non-blocking.Suggestions
key_mlbam,key_bbref, etc.) that callers sometimes use to retrieve a known set of players. A caller fetching 150 specific players bykey_mlbamwill silently receive only 100 with the default limit. Worth documenting in API docs or raisinglimitto 500 default for this endpoint specifically — but this is a design preference, not a correctness issue.Verdict: COMMENT
Implementation is correct and consistent with the established pagination pattern across the codebase. Posting as COMMENT rather than APPROVED due to Gitea's self-review restriction.
Automated review by Claude PR Reviewer
Implementation is correct and consistent with the pagination pattern established across the codebase. The limit guard (
max(0, min(limit, 500))) is properly placed after all filters and before the csv/json branch split. The ruff F541 fix is a clean side-effect. Approving.Implementation is correct and consistent with the pagination pattern established across the codebase. Approving.