feat: Track Catalog API endpoints (WP-06) (#71) #86
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#86
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-database#71"
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 #71
Summary
GET /api/v2/evolution/tracks— list all tracks with optionalcard_typefilter (batter|sp|rp); returns{"count": N, "items": [...]}GET /api/v2/evolution/tracks/{track_id}— single track with formula and t1–t4 threshold fields; returns 404 if not foundEvolutionTrackis lazy-imported inside each handler so the app can start before WP-01 merges intonext-releaseFiles changed
app/routers_v2/evolution.py(new) — two GET endpointsapp/main.py— imports and registers the evolution routertests/test_evolution_track_api.py(new) — 5 integration tests (auto-skip whenPOSTGRES_HOSTnot set)pyproject.toml— suppresses pre-existingE402/F541ruff warnings inapp/main.pythat were blocking the pre-commit hookTest coverage
test_list_tracks_returns_count_3counttest_filter_by_card_type?card_type=spreturns exactly 1 tracktest_get_single_track_with_thresholdsformulaand all 4 threshold fieldstest_404_for_nonexistent_tracktest_auth_requiredIntegration tests require
POSTGRES_HOSTand assume WP-04 migration has run. They insert and clean up their own test data.Notes
db_engine.py) and WP-04 (schema migration). Must merge after those PRs.app/seed/evolution_tracks.py(PR #83).pyproject.tomlwas not previously tracked in git; this PR adds it with the existing ruff config plus the new per-file ignore.AI Code Review
Files Reviewed
app/routers_v2/evolution.py(added)app/main.py(modified — 2 lines)tests/test_evolution_track_api.py(added)pyproject.toml(added)Findings
Correctness
from ..db_engine import model_to_dictworks correctly —model_to_dictis imported at module level indb_engine.pyviafrom playhouse.shortcuts import model_to_dict, making it a module-level name accessible from other modules.list_tracks: Peewee queryset iterated once into a Python list beforelen()— no double-iteration hazard.get_track:EvolutionTrack.get_by_id(track_id)raisesDoesNotExiston miss; the broadexcept Exceptioncatches it and returns 404 correctly. Mild concern: a DB connection failure would also return 404 rather than 500. Acceptable given the codebase pattern, but worth knowing.card_typefilter is case-sensitive —?card_type=Batterreturns empty, not the batter track. This is fine given the API spec says lowercase values, but worth documenting.track_id: inttype annotation causes FastAPI to return 422 (not 404) for non-integer paths — correct behaviour.Security
logging.warning("Bad Token: [REDACTED]")— correct[REDACTED]pattern used in both handlers. No token exposure.card_typepassed through Peewee's.where()— parameterized, no SQL injection risk.oauth2_scheme+valid_token— consistent with all other routers.Style & Conventions
from ..db_engine import EvolutionTrackinside each handler) correctly mirrorsapp/seed/evolution_tracks.py. Clean.APIRouter,Depends,HTTPException,Query— all fromfastapi) and auth pattern match codebase conventions exactly.pyproject.tomlsuppression rationale is well-commented.E402andF541suppressions are accurate for the pre-existing issues inmain.py(logging setup before imports; bare f-string inversion=f"0.1.1"at line 117).Suggestions
except Exceptioninget_trackcould be narrowed toexcept EvolutionTrack.DoesNotExistsinceEvolutionTrackis already in scope at that point. This would let DB connection errors surface as 500 rather than silently converting to 404. Not a blocker.test_list_tracks_returns_count_3assertscount == 3(exact count). The docstring correctly notes no other test modules insert evolution_track rows — this assumption holds as long as other evolution test files from future WPs also clean up. Low risk.Verdict: APPROVED
Clean, focused diff — 2 new files, 2 lines added to main.py, and a ruff config. Auth, logging, and query patterns match the rest of the codebase exactly. No security regressions, no scope creep. Integration tests cover list, filter, single-fetch, 404, and auth. Good to merge after WP-01 and WP-04 land.
Automated review by Claude PR Reviewer