|
1 | 1 | import typing |
2 | 2 |
|
3 | 3 | import litestar |
| 4 | +from litestar.di import NamedDependency # noqa: TC002 |
4 | 5 | from litestar.params import FromPath # noqa: TC002 |
5 | 6 |
|
6 | 7 | from app import models, schemas |
7 | 8 | from app.repositories import CardsRepository # noqa: TC001 |
8 | 9 |
|
9 | 10 |
|
10 | 11 | @litestar.get("/decks/{deck_id:int}/cards/") |
11 | | -async def list_cards(deck_id: FromPath[int], cards_repository: CardsRepository) -> schemas.Cards: |
| 12 | +async def list_cards(deck_id: FromPath[int], cards_repository: NamedDependency[CardsRepository]) -> schemas.Cards: |
12 | 13 | objects = await cards_repository.list_for_deck(deck_id) |
13 | 14 | return schemas.Cards.from_models(objects) |
14 | 15 |
|
15 | 16 |
|
16 | 17 | @litestar.get("/cards/{card_id:int}/") |
17 | | -async def get_card(card_id: FromPath[int], cards_repository: CardsRepository) -> schemas.Card: |
| 18 | +async def get_card(card_id: FromPath[int], cards_repository: NamedDependency[CardsRepository]) -> schemas.Card: |
18 | 19 | instance = await cards_repository.get_one(models.Card.id == card_id) |
19 | 20 | return schemas.Card.model_validate(instance) |
20 | 21 |
|
21 | 22 |
|
22 | 23 | @litestar.post("/decks/{deck_id:int}/cards/") |
23 | 24 | async def create_cards( |
24 | | - deck_id: FromPath[int], data: list[schemas.CardCreate], cards_repository: CardsRepository |
| 25 | + deck_id: FromPath[int], data: list[schemas.CardCreate], cards_repository: NamedDependency[CardsRepository] |
25 | 26 | ) -> schemas.Cards: |
26 | 27 | objects = await cards_repository.add_cards(deck_id, data) |
27 | 28 | return schemas.Cards.from_models(objects) |
28 | 29 |
|
29 | 30 |
|
30 | 31 | @litestar.put("/decks/{deck_id:int}/cards/") |
31 | 32 | async def update_cards( |
32 | | - deck_id: FromPath[int], data: list[schemas.Card], cards_repository: CardsRepository |
| 33 | + deck_id: FromPath[int], data: list[schemas.Card], cards_repository: NamedDependency[CardsRepository] |
33 | 34 | ) -> schemas.Cards: |
34 | 35 | objects = await cards_repository.upsert_cards(deck_id, data) |
35 | 36 | return schemas.Cards.from_models(objects) |
|
0 commit comments