feat: add limit/pagination to events endpoint (#147) #156

Merged
cal merged 6 commits from issue/147-feat-add-limit-pagination-to-events-endpoint into main 2026-03-24 12:09:46 +00:00
Collaborator

Closes #147

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

Changes

  • app/routers_v2/events.py: Added limit: Optional[int] = 100 parameter to v1_events_get. Applied all_events.limit(max(0, min(limit, 500))) after all filters, before the CSV/JSON branch — consistent with the pattern used in notifications, scout_claims, rewards, scout_opportunities, and batstats endpoints.

Test results

No test suite. Change verified by reading back the modified file and confirming the diff is minimal and correct. Ruff pre-commit hook passed.

Closes #147 Adds an optional `limit` query parameter (default 100, max 500) to `GET /api/v2/events`. ## Changes - `app/routers_v2/events.py`: Added `limit: Optional[int] = 100` parameter to `v1_events_get`. Applied `all_events.limit(max(0, min(limit, 500)))` after all filters, before the CSV/JSON branch — consistent with the pattern used in notifications, scout_claims, rewards, scout_opportunities, and batstats endpoints. ## Test results No test suite. Change verified by reading back the modified file and confirming the diff is minimal and correct. Ruff pre-commit hook passed.
Claude added 1 commit 2026-03-24 06:32:31 +00:00
Closes #147

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

AI Code Review

Files Reviewed

  • app/routers_v2/events.py (modified)

Findings

Correctness

  • limit: Optional[int] = 100 added to v1_events_get signature. Optional already imported at line 2 — no missing import.
  • all_events.limit(max(0, min(limit, 500))) applied after all filters (name, in_desc, active), before the if csv: branch — both CSV and JSON response paths correctly honour the limit.
  • Clamping formula max(0, min(limit, 500)) guards negative values (floors to 0) and oversized values (caps at 500). Identical to the pattern in notifications, scout_claims, rewards, scout_opportunities, and batstats endpoints.

Security

  • No issues. limit is typed Optional[int]; FastAPI validates the type before the function executes. ORM handles query parameterisation.

Style & Conventions

  • Change is minimal and focused. Follows the established pagination pattern exactly — this is the 6th endpoint to receive this treatment, and the implementation is character-for-character consistent with the prior five.

Suggestions

  • MINOR: all_events.count() (line 55) is called after .limit() is applied, so the count field in the JSON response reflects the limited count, not the total number of matching events. This is the same pre-existing pattern across all other paginated endpoints — a follow-up issue to add a total field project-wide would address it consistently.
  • MINOR: limit=0 returns an empty response even when events exist (lower bound of the clamp). Same pedantic edge case present in all prior pagination PRs — non-blocking.

Verdict: APPROVED

Clean, minimal, correct. Follows the pagination pattern established across the five prior endpoints without deviation. No blocking issues.

Note: Posted as COMMENT due to Gitea self-review restriction — verdict is APPROVED.


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `app/routers_v2/events.py` (modified) ### Findings #### Correctness - `limit: Optional[int] = 100` added to `v1_events_get` signature. `Optional` already imported at line 2 — no missing import. - `all_events.limit(max(0, min(limit, 500)))` applied after all filters (`name`, `in_desc`, `active`), before the `if csv:` branch — both CSV and JSON response paths correctly honour the limit. - Clamping formula `max(0, min(limit, 500))` guards negative values (floors to 0) and oversized values (caps at 500). Identical to the pattern in notifications, scout_claims, rewards, scout_opportunities, and batstats endpoints. #### Security - No issues. `limit` is typed `Optional[int]`; FastAPI validates the type before the function executes. ORM handles query parameterisation. #### Style & Conventions - Change is minimal and focused. Follows the established pagination pattern exactly — this is the 6th endpoint to receive this treatment, and the implementation is character-for-character consistent with the prior five. #### Suggestions - **MINOR**: `all_events.count()` (line 55) is called after `.limit()` is applied, so the `count` field in the JSON response reflects the limited count, not the total number of matching events. This is the same pre-existing pattern across all other paginated endpoints — a follow-up issue to add a `total` field project-wide would address it consistently. - **MINOR**: `limit=0` returns an empty response even when events exist (lower bound of the clamp). Same pedantic edge case present in all prior pagination PRs — non-blocking. ### Verdict: APPROVED Clean, minimal, correct. Follows the pagination pattern established across the five prior endpoints without deviation. No blocking issues. > Note: Posted as COMMENT due to Gitea self-review restriction — verdict is APPROVED. --- *Automated review by Claude PR Reviewer*
Claude added
ai-reviewed
and removed
ai-reviewing
labels 2026-03-24 06:46:54 +00:00
cal approved these changes 2026-03-24 12:04:26 +00:00
Dismissed
cal left a comment
Owner

Approved — reviewer verdict is APPROVED, implementation is clean and consistent with the established pagination pattern.

Approved — reviewer verdict is APPROVED, implementation is clean and consistent with the established pagination pattern.
cal added 1 commit 2026-03-24 12:05:35 +00:00
cal dismissed cal’s review 2026-03-24 12:06:28 +00:00
Reason:

Re-approving after rebase

cal approved these changes 2026-03-24 12:06:32 +00:00
Dismissed
cal left a comment
Owner

Re-approving on rebased head — same clean, minimal change. Reviewer verdict remains APPROVED.

Re-approving on rebased head — same clean, minimal change. Reviewer verdict remains APPROVED.
cal added 1 commit 2026-03-24 12:07:18 +00:00
cal added 1 commit 2026-03-24 12:07:50 +00:00
cal dismissed cal’s review 2026-03-24 12:07:56 +00:00
Reason:

Re-approving after another rebase

cal approved these changes 2026-03-24 12:07:57 +00:00
Dismissed
cal left a comment
Owner

Approved on rebased head.

Approved on rebased head.
cal added 1 commit 2026-03-24 12:08:41 +00:00
cal dismissed cal’s review 2026-03-24 12:08:48 +00:00
Reason:

rebase

cal approved these changes 2026-03-24 12:08:48 +00:00
Dismissed
cal left a comment
Owner

Approved.

Approved.
cal added 1 commit 2026-03-24 12:09:25 +00:00
cal dismissed cal’s review 2026-03-24 12:09:41 +00:00
Reason:

rebase

cal approved these changes 2026-03-24 12:09:41 +00:00
cal left a comment
Owner

Approved.

Approved.
cal merged commit f2e10bcf2f into main 2026-03-24 12:09:46 +00:00
cal deleted branch issue/147-feat-add-limit-pagination-to-events-endpoint 2026-03-24 12:09:47 +00:00
Sign in to join this conversation.
No description provided.