Skip to content

feat(api): Olufemi - API validation, pagination, stats & audit logging#1

Merged
Goldokpa merged 4 commits into
mainfrom
feature/api-olufemi-improvements
Mar 16, 2026
Merged

feat(api): Olufemi - API validation, pagination, stats & audit logging#1
Goldokpa merged 4 commits into
mainfrom
feature/api-olufemi-improvements

Conversation

@Goldokpa
Copy link
Copy Markdown
Member

Summary

Four API improvements by Olufemi Taiwo (femi23) - API & Data Quality Lead:

  • Bbox & date validation — validates coordinates are in range, west < east, south < north, dates in YYYY-MM-DD format
  • Pagination on /api/runs — adds offset param and returns {total, limit, offset, runs} envelope for frontend page controls
  • Stats endpoint — new /api/runs/stats returning run counts by status/analysis type + alert summary for dashboard KPIs
  • Audit logging middleware — logs every request (method, path, status, duration, IP) + adds X-Response-Time-Ms response header

Test plan

  • Start API and hit /api/runs/stats — confirm response shape
  • Send invalid bbox (e.g. 3 values) to /api/predict/json — confirm 422 error
  • Hit /api/runs?limit=10&offset=0 — confirm pagination envelope returned
  • Check server logs for audit log lines on each request

🤖 Generated with Claude Code

femi23 added 4 commits March 16, 2026 20:05
- Validate bbox has exactly 4 values [west, south, east, north]
- Enforce longitude bounds (-180 to 180) and latitude bounds (-90 to 90)
- Ensure west < east and south < north
- Validate date strings follow YYYY-MM-DD format
- Ensure start_date is earlier than end_date
- Add offset query parameter for cursor-based pagination
- Return total record count alongside results for frontend page controls
- Restructure response to {total, limit, offset, runs} envelope
- Refactor WHERE clause building to avoid SQL injection via safe parameterisation
- Returns total run count, completed runs in last 7 days
- Breakdown by status (pending, running, completed, failed)
- Breakdown by analysis type (deforestation, ice_melting, flooding)
- Alert summary: total alerts and unacknowledged count
- Feeds directly into the frontend Dashboard KPI summary cards
- Log every request: method, path, status code, duration_ms, client IP
- Attach X-Response-Time-Ms header to all responses for frontend monitoring
- Uses Starlette BaseHTTPMiddleware for non-blocking request interception
- Helps trace slow endpoints and detect unusual access patterns in production
@Goldokpa Goldokpa merged commit 3bcba57 into main Mar 16, 2026
Goldokpa added a commit that referenced this pull request Mar 23, 2026
…ments

feat(api): Olufemi - API validation, pagination, stats & audit logging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants