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