games-xxwif7/endpoints/footing.post.py
2025-03-25 07:36:18 +01:00

44 lines
975 B
Python

from fastapi import APIRouter, HTTPException
import uuid
games = [] # In-memory storage
router = APIRouter()
@router.post("/footing")
async def save_game(
title: str,
genre: str,
platform: str
):
"""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,
"title": title,
"genre": genre,
"platform": platform
}
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 from the database"""
if request.method != "GET":
raise HTTPException(status_code=405, detail="Method Not Allowed")
return {
"method": "GET",
"_verb": "get",
"games": games
}