Skip to content

Commit

Permalink
added get all games
Browse files Browse the repository at this point in the history
  • Loading branch information
ychebyshev committed Feb 1, 2024
1 parent 7fa294e commit 85397ed
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion shvatka/api/routes/game.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Sequence

from fastapi import APIRouter
from fastapi.params import Depends

from shvatka.api.dependencies import dao_provider, player_provider, active_game_provider
from shvatka.api.models import responses
from shvatka.core.models import dto
from shvatka.core.services.game import get_authors_games
from shvatka.core.services.game import get_authors_games, get_completed_games
from shvatka.infrastructure.db.dao.holder import HolderDao


Expand All @@ -21,8 +23,16 @@ async def get_active_game(
return responses.Game.from_core(game)


async def get_all_games(
dao: HolderDao = Depends(dao_provider), # type: ignore[assignment]
) -> Sequence[responses.Game]:
games = await get_completed_games(dao.game)
return [responses.Game.from_core(game) for game in games]


def setup() -> APIRouter:
router = APIRouter(prefix="/games")
router.add_api_route("", get_all_games, methods=["GET"])
router.add_api_route("/my", get_my_games_list, methods=["GET"])
router.add_api_route("/active", get_active_game, methods=["GET"])
return router

0 comments on commit 85397ed

Please sign in to comment.