Add requirements, cli commands. New project structure

This commit is contained in:
2024-05-10 12:15:18 +04:00
parent e426c281b9
commit 698cca0aeb
12 changed files with 94 additions and 33 deletions

20
routes/games.py Normal file
View File

@@ -0,0 +1,20 @@
from fastapi import APIRouter, Depends, HTTPException
from database import *
router = APIRouter(prefix="/games", tags=["Games"])
@router.get("/", response_model=list[Game])
async def get_games(db: AsyncSession = Depends(get_session)):
try: return await crud.get_games(db)
except Exception as ex: raise HTTPException(500)
@router.get("/{game_id}", response_model=Game)
async def get_game(game_id: int, db: AsyncSession = Depends(get_session)):
return await crud.get_game(db, game_id)
@router.post("/", response_model=Game)
async def add_game(game: GameCreate, user_id: int, db:AsyncSession = Depends(get_session)):
try: return await crud.add_game(db, game, user_id)
except Exception as ex: raise HTTPException(500)