Add POST endpoint for /ames
This commit is contained in:
parent
7057bbf170
commit
d7952fbe6d
30
endpoints/ames.post.py
Normal file
30
endpoints/ames.post.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Entity: Game
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from typing import List
|
||||||
|
from core.database import get_db
|
||||||
|
from models.game import Game
|
||||||
|
from schemas.game import GameSchema, GameCreate
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/games", status_code=200, response_model=List[GameSchema])
|
||||||
|
async def get_games(
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
"""Get all games"""
|
||||||
|
games = db.query(Game).all()
|
||||||
|
return games
|
||||||
|
|
||||||
|
@router.post("/games", status_code=201, response_model=GameSchema)
|
||||||
|
async def create_game(
|
||||||
|
game: GameCreate,
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
"""Create a new game"""
|
||||||
|
new_game = Game(**game.dict())
|
||||||
|
db.add(new_game)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(new_game)
|
||||||
|
return new_game
|
Loading…
x
Reference in New Issue
Block a user