Update code in endpoints/game.post.py
This commit is contained in:
parent
bff432329e
commit
f12a422f6e
46
endpoints/game.post.py
Normal file
46
endpoints/game.post.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
games = [] # In-memory storage
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/game")
|
||||||
|
async def save_game(
|
||||||
|
game_name: str,
|
||||||
|
developer: str,
|
||||||
|
genre: str,
|
||||||
|
price: float
|
||||||
|
):
|
||||||
|
"""Save a new game to the database"""
|
||||||
|
if request.method != "POST":
|
||||||
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||||
|
|
||||||
|
game_id = str(uuid.uuid4())
|
||||||
|
game = {
|
||||||
|
"id": game_id,
|
||||||
|
"name": game_name,
|
||||||
|
"developer": developer,
|
||||||
|
"genre": genre,
|
||||||
|
"price": price
|
||||||
|
}
|
||||||
|
games.append(game)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "Game saved successfully",
|
||||||
|
"game_id": game_id,
|
||||||
|
"method": "POST",
|
||||||
|
"_verb": "post"
|
||||||
|
}
|
||||||
|
|
||||||
|
@router.get("/games")
|
||||||
|
async def get_games():
|
||||||
|
"""Fetch all games from the database"""
|
||||||
|
if request.method != "GET":
|
||||||
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"games": games,
|
||||||
|
"method": "GET",
|
||||||
|
"_verb": "get"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user