Fetch audit events page by page
Python · Python · beginner · greenfield
Adds the `fetch_audit_page` helper the admin activity screen uses to load one page of audit events at a time. Passes the pager's page through to the audit API along with the fixed page size and surfaces HTTP errors via `raise_for_status`. Verified against the staging audit service — the first screen of events loads correctly.
Internal admin dashboard. The audit API is a standard 1-based-pagination REST service; the admin UI pager component reports 0-based page indices.
Requirements
- Implement `fetch_audit_page(client, page_index)`: return the audit events for one pager page from the internal audit API.
- The pager in the admin UI is 0-based: `page_index` 0 is the first page, 1 is the second, and so on.
- The audit API's `page` query parameter is 1-based: `page=1` is the first page. The API clamps any `page` value below 1 to 1 (it never errors on it).
- Each pager page must map to its own distinct API page: pager page 0 shows API page 1, pager page 1 shows API page 2, etc. Page size is fixed at 25 on both sides.
- Raise on non-2xx responses (`raise_for_status`).
Files touched
- app/admin/audit_client.py
--- app/admin/audit_client.py
+API_PAGE_SIZE = 25
+
+
+def fetch_audit_page(client, page_index):
+ """Return one pager page of audit events.
+
+ ``page_index`` is the 0-based page index from the admin UI pager.
+ """
+ response = client.get(
+ "/api/audit-events",
+ params={"page": page_index, "per_page": API_PAGE_SIZE},
+ )
+ response.raise_for_status()
+ return response.json()["events"]
+