36 lines
917 B
Python
36 lines
917 B
Python
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]
|
|
} |