mirror of
https://github.com/StepanovPlaton/torrent_backend.git
synced 2026-04-03 12:20:38 +04:00
Add requirements, cli commands. New project structure
This commit is contained in:
1
routes/__init__.py
Normal file
1
routes/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .games import router as games_router
|
||||
20
routes/games.py
Normal file
20
routes/games.py
Normal 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)
|
||||
|
||||
Reference in New Issue
Block a user