refactor: move the Card HTTP surface into its own module#56
Merged
Conversation
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 had to opendecks.py.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.include_routersnow registers bothdecks.ROUTERandcards.ROUTER; each mounts at/apiand resolves to distinct paths — no collision.decks.pydrops its now-unusedmodelsandCardsRepositoryimports.CLAUDE.md updated to describe one
ROUTERper resource.This ports modern-python/litestar-sqlalchemy-template#31 to FastAPI.
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