Skip to content

Add athlete audit logging API and per-athlete history retrieval#9

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/implement-athlete-logging-endpoints
Draft

Add athlete audit logging API and per-athlete history retrieval#9
Copilot wants to merge 3 commits into
mainfrom
copilot/implement-athlete-logging-endpoints

Conversation

Copilot AI commented May 18, 2026

Copy link
Copy Markdown

This PR adds backend support for daily athlete audit metrics ingestion and historical retrieval, including strict input validation and expected API error semantics (400 for invalid input, 404 for missing athlete).

  • API surface

    • Added POST /api/v1/audit to persist a daily audit entry.
    • Added GET /api/v1/athletes/{athlete_id}/history to fetch all audit logs for one athlete, sorted newest-first.
  • Domain logic and persistence

    • Extended athlete_profiles.py with audit-log storage (backend/data/audit_logs.json), load/save helpers, and service functions:
      • add_audit_log(...)
      • get_athlete_audit_history(...)
    • Enforced payload constraints:
      • athlete_id required and must exist
      • date required in YYYY-MM-DD
      • scores required, non-empty object
      • every score must be an integer in [1, 10]
      • optional notes must be a string when provided
  • Error handling contract

    • Invalid payloads return 400 Bad Request with clear validation details.
    • Unknown athlete IDs return 404 Not Found on both write and history retrieval paths.
  • Documentation

    • Updated API endpoint table in README.md with the two new /api/v1/... routes.
  • Focused tests

    • Added backend/tests/test_audit_api.py covering:
      • successful create + history retrieval ordering
      • invalid score range (400)
      • missing athlete on create (404)
      • missing athlete on history lookup (404)
# main.py
@app.post("/api/v1/audit")
async def create_audit_log(req: dict):
    try:
        result = add_audit_log(req)
        return {"status": "created", "audit": result}
    except ValueError as e:
        raise HTTPException(status_code=400, detail=str(e))
    except LookupError as e:
        raise HTTPException(status_code=404, detail=str(e))

Copilot AI and others added 2 commits May 18, 2026 18:30
Copilot AI changed the title [WIP] Add REST API endpoints for athlete logging and retrieval Add athlete audit logging API and per-athlete history retrieval May 18, 2026
Copilot AI requested a review from unoursmarin May 18, 2026 18:32
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.

#Issue 2: Implement REST API endpoints for Athlete Logging and Retrieval

2 participants