2025-03-25 08:48:51 +01:00

67 lines
1.6 KiB
Python

```python
from typing import List
from pydantic import BaseModel, Field
from datetime import datetime
from uuid import uuid4
class GameCreate(GameBase):
pass
class GameUpdate(GameBase):
pass
class GameInDBBase(GameBase):
id: str = Field(..., description="Unique identifier for the game")
created_at: datetime = Field(..., description="Timestamp of when the game was created")
updated_at: datetime = Field(..., description="Timestamp of when the game was last updated")
class Config:
orm_mode = True
class Game(GameInDBBase):
pass
class GameInDB(GameInDBBase):
pass
games = [] # In-memory storage
from fastapi import APIRouter, HTTPException
router = APIRouter()
@router.post("/footballing", status_code=201)
async def create_game(game: GameCreate):
"""Create a new game"""
if request.method != "POST":
raise HTTPException(status_code=405, detail="Method Not Allowed")
new_game = Game(
id=str(uuid4()),
name=game.name,
description=game.description,
genre=game.genre,
release_date=game.release_date,
created_at=datetime.now(),
updated_at=datetime.now()
)
games.append(new_game)
return {
"method": "POST",
"_verb": "post",
"message": "Game created successfully",
"game": new_game
}
@router.get("/footballing", response_model=List[GameInDB])
async def get_games():
"""Get all games"""
if request.method != "GET":
raise HTTPException(status_code=405, detail="Method Not Allowed")
return games
```