Skip to content

refactor: move the Card HTTP surface into its own module#31

Merged
lesnik512 merged 1 commit into
mainfrom
refactor/split-card-routes
Jun 26, 2026
Merged

refactor: move the Card HTTP surface into its own module#31
lesnik512 merged 1 commit into
mainfrom
refactor/split-card-routes

Conversation

@lesnik512

Copy link
Copy Markdown
Member

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 opened decks.py. This also contradicted the project's own convention (CLAUDE.md: one module per resource, each with its own Router).

Change

Move all four card handlers into app/api/cards.py with its own ROUTER:

Handler Path
list_cards GET /decks/{deck_id}/cards/
create_cards POST /decks/{deck_id}/cards/
update_cards PUT /decks/{deck_id}/cards/
get_card GET /cards/{card_id}/

The deck-nested /decks/{deck_id}/cards/ routes move too — they operate on Card rows (CardsRepository, return schemas.Cards); the /decks/{deck_id}/ prefix is just scoping, not ownership. Handlers keep their full paths, so the URL tree is unchanged.

build_app now registers route_handlers=[decks.ROUTER, cards.ROUTER]. Both Routers mount at /api and resolve to distinct paths — no collision.

CLAUDE.md updated: "single ROUTER" → "one Router per 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% coveragecards.py and decks.py both fully covered.

🤖 Generated with Claude Code

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 lesnik512 merged commit 46b5cfb into main Jun 26, 2026
2 checks passed
@lesnik512 lesnik512 deleted the refactor/split-card-routes branch June 26, 2026 10:36
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>
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.

1 participant