Update code in endpoints/footing.post.py

This commit is contained in:
Backend IM Bot 2025-03-25 07:37:00 +01:00
parent 7964799af1
commit dca2be4296

View File

@ -7,7 +7,8 @@ router = APIRouter()
@router.post("/footing")
async def save_game(
title: str,
name: str,
description: str,
genre: str,
platform: str
):
@ -18,8 +19,9 @@ async def save_game(
game_id = str(uuid.uuid4())
game = {
"id": game_id,
"title": title,
"genre": genre,
"name": name,
"description": description,
"genre": genre,
"platform": platform
}
games.append(game)
@ -33,12 +35,15 @@ async def save_game(
@router.get("/games")
async def get_games():
"""Fetch all saved games from the database"""
"""Fetch all saved games"""
if request.method != "GET":
raise HTTPException(status_code=405, detail="Method Not Allowed")
return {
"method": "GET",
"_verb": "get",
"method": "GET",
"_verb": "get",
"games": games
}
}
```
This code provides an endpoint `/footing` to save a new game to an in-memory list called `games`. It also includes a `GET` endpoint `/games` to fetch all saved games. The `save_game` function checks if the request method is `POST` and raises a `405 Method Not Allowed` error otherwise. It creates a new `game` dictionary with the provided parameters and a unique `game_id`, appends it to the `games` list, and returns a success message with the `game_id`. The `get_games` function checks if the request method is `GET` and returns the list of `games`.