Skip to content

refactor: deepen Deck and Card data-access modules#51

Merged
lesnik512 merged 2 commits into
mainfrom
refactor/deepen-deck-card-repositories
Jun 26, 2026
Merged

refactor: deepen Deck and Card data-access modules#51
lesnik512 merged 2 commits into
mainfrom
refactor/deepen-deck-card-repositories

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

The DecksRepository / CardsRepository were empty subclasses of advanced-alchemy's service, so their interface was the entire generic surface and the query knowledge — filters, eager-load options, schema→model mapping — leaked into every HTTP handler.

This deepens both modules: a small set of named methods now absorbs that knowledge behind the interface.

Method Absorbs
DecksRepository.fetch_with_cards(deck_id) id filter + selectinload(cards)
CardsRepository.list_for_deck(deck_id) deck_id filter
CardsRepository.add_cards(deck_id, cards) model_dump + deck_id injection + Card(...) build
CardsRepository.upsert_cards(deck_id, cards) same mapping, upsert semantics

Handlers now name the intent and hand over the request schemas they already hold.

Ports modern-python/litestar-sqlalchemy-template#26 to this template, adapted to FastAPI idioms (the typing.cast(...) response convention is preserved).

Scope (deliberately narrow)

  • advanced-alchemy's generic surface stays visible (additive, not a narrowed interface) — the template still demonstrates the library.
  • Methods return ORM models; output serialization stays at the HTTP edge via typing.cast.
  • fetch_with_cards returns Deck | None — the existing 404 behaviour is byte-for-byte unchanged.
  • list_decks / create_deck / update_deck / get_card left alone — they carry no real leak.
  • No new tests: the existing HTTP suite already crosses all four methods.

Verification

  • just test → 19 passed, 100% coverage (incl. repositories.py)
  • ruff format --check / ruff check --no-fix / ty check clean

🤖 Generated with Claude Code

lesnik512 and others added 2 commits June 26, 2026 11:35
The DecksRepository / CardsRepository were empty subclasses of
advanced-alchemy's service, so their interface was the entire generic
surface and the query knowledge — filters, eager-load options,
schema→model mapping — leaked into every HTTP handler.

Deepen both modules with a small set of named methods that absorb that
knowledge behind the interface:

- DecksRepository.fetch_with_cards — id filter + selectinload(cards)
- CardsRepository.list_for_deck    — deck_id filter
- CardsRepository.add_cards        — model_dump + deck_id + Card(...) build
- CardsRepository.upsert_cards     — same mapping, upsert semantics

Handlers now name the intent and hand over the request schemas they
already hold. Additive only: advanced-alchemy's generic surface stays
visible so the template still demonstrates the library. Behaviour is
unchanged — fetch_with_cards returns Deck | None and the existing 404
path is byte-for-byte the same.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 9c49356 into main Jun 26, 2026
2 checks passed
@lesnik512 lesnik512 deleted the refactor/deepen-deck-card-repositories branch June 26, 2026 08:52
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