refactor: deepen Deck and Card data-access modules#51
Merged
Conversation
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>
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.
What
The
DecksRepository/CardsRepositorywere 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.
DecksRepository.fetch_with_cards(deck_id)selectinload(cards)CardsRepository.list_for_deck(deck_id)deck_idfilterCardsRepository.add_cards(deck_id, cards)model_dump+deck_idinjection +Card(...)buildCardsRepository.upsert_cards(deck_id, cards)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)
typing.cast.fetch_with_cardsreturnsDeck | None— the existing 404 behaviour is byte-for-byte unchanged.list_decks/create_deck/update_deck/get_cardleft alone — they carry no real leak.Verification
just test→ 19 passed, 100% coverage (incl.repositories.py)ruff format --check/ruff check --no-fix/ty checkclean🤖 Generated with Claude Code