Update code in endpoints/footin.post.py
This commit is contained in:
parent
3dac795d8f
commit
6c1637c55d
36
endpoints/footin.post.py
Normal file
36
endpoints/footin.post.py
Normal file
@ -0,0 +1,36 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
|
||||
games = [] # In-memory storage
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/footin")
|
||||
async def save_game(game: GameSchema):
|
||||
"""Save a new game to the database"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
game_dict = game.dict()
|
||||
game_dict["id"] = len(games) + 1
|
||||
games.append(game_dict)
|
||||
|
||||
return {
|
||||
"method": "POST",
|
||||
"_verb": "post",
|
||||
"message": "Game saved successfully",
|
||||
"game": game_dict
|
||||
}
|
||||
|
||||
@router.post("/footin")
|
||||
async def get_games():
|
||||
"""Fetch all games from the database"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
return {
|
||||
"method": "POST",
|
||||
"_verb": "post",
|
||||
"games": [game for game in games]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user