Small fixes

This commit is contained in:
2024-05-10 16:44:46 +04:00
parent a45c2dfee2
commit fd5b19e6a9
12 changed files with 94 additions and 61 deletions

View File

@@ -1,27 +1,29 @@
from fastapi import APIRouter, Depends, HTTPException, UploadFile
from fastapi import APIRouter, Depends, HTTPException
from database import *
from file_handler import *
router = APIRouter(prefix="/games", tags=["Games"])
games_router = APIRouter(prefix="/games", tags=["Games"])
@router.get("/", response_model=list[Game])
@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)
try:
return await crud.get_games(db)
except Exception:
raise HTTPException(500)
@router.get("/{game_id}", response_model=Game)
@games_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)):
@games_router.post("/", response_model=Game)
async def add_game(game: GameCreate,
user_id: int,
db: AsyncSession = Depends(get_session)):
try:
torrent_filename = save_torrent_file(torrent, game.title)
cover_filename = save_image(cover, game.title, "cover")
return await crud.add_game(db, game, user_id)
except Exception as ex:
except Exception:
raise HTTPException(500)