refactor: move the Card HTTP surface into its own module#31
Merged
Conversation
The four card handlers lived in app/api/decks.py, scattering the Card
concept and contradicting the project's own convention (one module per
resource, each with its own Router). To read the Card HTTP surface you
had to open a file named decks.py.
Move all four card handlers — including the deck-nested
/decks/{deck_id}/cards/ routes — into app/api/cards.py with its own
ROUTER. build_app now registers route_handlers=[decks.ROUTER,
cards.ROUTER]; both mount at /api and resolve to distinct paths. The
URL tree is unchanged. Update CLAUDE.md to describe one Router per
resource.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lesnik512
added a commit
to modern-python/fastapi-sqlalchemy-template
that referenced
this pull request
Jun 26, 2026
The four card handlers lived in app/api/decks.py, scattering the Card
concept across model / schema / repository / a misnamed handler file. To
read the Card HTTP surface you had to open decks.py.
Move all four card handlers into app/api/cards.py with its own ROUTER.
The deck-nested /decks/{deck_id}/cards/ routes move too -- they operate
on Card rows (CardsRepository, return schemas.Cards); the /decks prefix
is just scoping, not ownership. Handlers keep their full paths, so the
URL tree is unchanged.
include_routers now registers both decks.ROUTER and cards.ROUTER; each
mounts at /api and resolves to distinct paths -- no collision. Ports
modern-python/litestar-sqlalchemy-template#31 to FastAPI.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The four card handlers lived in
app/api/decks.py, scattering the Card concept across model / schema / repository / a misnamed handler file. To read the Card HTTP surface you openeddecks.py. This also contradicted the project's own convention (CLAUDE.md: one module per resource, each with its ownRouter).Change
Move all four card handlers into
app/api/cards.pywith its ownROUTER:list_cardsGET /decks/{deck_id}/cards/create_cardsPOST /decks/{deck_id}/cards/update_cardsPUT /decks/{deck_id}/cards/get_cardGET /cards/{card_id}/The deck-nested
/decks/{deck_id}/cards/routes move too — they operate onCardrows (CardsRepository, returnschemas.Cards); the/decks/{deck_id}/prefix is just scoping, not ownership. Handlers keep their full paths, so the URL tree is unchanged.build_appnow registersroute_handlers=[decks.ROUTER, cards.ROUTER]. BothRouters mount at/apiand resolve to distinct paths — no collision.CLAUDE.md updated: "single
ROUTER" → "oneRouterper resource", which is what the code now does (and what the convention always said to do).Tests
Pure file move; tests address routes via the HTTP client, not handler imports. 19 passed, 100% coverage —
cards.pyanddecks.pyboth fully covered.🤖 Generated with Claude Code