feat: add limit/pagination to rewards endpoint (#139) #152
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#152
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/139-feat-add-limit-pagination-to-rewards-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 #139
Adds optional
limitquery parameter toGET /api/v2/rewards.100500(capped viamax(0, min(limit, 500))— guards negative values)Files changed:
app/routers_v2/rewards.pyOther observations: The file was auto-reformatted by ruff (single→double quotes, indentation normalization) during the pre-commit hook — cosmetic diff is wider than the functional change but all ruff checks pass.
AI Code Review
Files Reviewed
app/routers_v2/rewards.py(modified).gitea/workflows/build.yml(modified — pre-existing in main, see note)Findings
Correctness
limit: Optional[int] = 100parameter added correctly with appropriate default.limit = max(0, min(limit, 500))correctly guards both negative values and the upper bound — improvement over the PR #150 pattern which only usedmin(limit, 500).name,team_id,created_after,in_name,season,week) and after the secondcount() == 0guard, before the CSV/JSON branching. Placement is correct.Security
valid_token) unchanged.[REDACTED]token logging preserved correctly.Style & Conventions
Suggestions
MINOR —
countfield reflects limited count, not total matching rows. Afterall_rewards = all_rewards.limit(limit)is applied,all_rewards.count()wraps the limited query in a subquery, so thecountkey in the JSON response reflects the number of rows returned (≤ limit), not the total number of matching rewards. This is the same pre-existing pattern as the notifications endpoint (PR #150) and scout_claims endpoint (PR #151). Non-blocking given consistency with the rest of the codebase, but pagination callers may find it misleading.MINOR —
limit=0returns empty results even when rewards exist.max(0, min(0, 500))=0→LIMIT 0in SQL. If a caller passes?limit=0, the response is{"count": 0, "rewards": []}despite matching rows existing. Pedantic edge case (who requests 0 rows?), but worth noting. A lower bound of1instead of0would prevent it.INFORMATIONAL — build.yml diff is a no-op. The branch was not rebased onto current
main. The build.yml changes in this diff (dev tag trigger, local volume cache) correspond to commitsc185d72andd0f45d5, which are already inmain. Merging this PR will not alter.gitea/workflows/build.yml. Same pattern as PRs #150 and #151.Verdict: COMMENT
Implementation is correct and follows the established pattern. The
max(0, min(limit, 500))guard correctly addresses the negative-limit bug from PR #150. No blockers — thecountfield quirk andlimit=0edge case are both non-blocking observations consistent with patterns already present in the codebase.Automated review by Claude PR Reviewer
LGTM. Reviewer flagged two non-blocking observations (count reflects limited rows, limit=0 edge case) — both consistent with established patterns in #150 and #151. Approving.