Update code in endpoints/footb.post.py
This commit is contained in:
parent
68f3d9698d
commit
257c8ed14b
@ -0,0 +1,67 @@
|
||||
```python
|
||||
from typing import List
|
||||
from pydantic import BaseModel, Field
|
||||
from sqlalchemy import Column, Integer, String, Boolean
|
||||
from database import Base
|
||||
|
||||
# Game Model
|
||||
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String)
|
||||
description = Column(String)
|
||||
is_active = Column(Boolean, default=True)
|
||||
|
||||
# Game Schema
|
||||
|
||||
|
||||
class GameCreate(GameBase):
|
||||
pass
|
||||
|
||||
class GameUpdate(GameBase):
|
||||
is_active: bool = Field(default=True)
|
||||
|
||||
class GameOut(GameBase):
|
||||
id: int
|
||||
is_active: bool
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
# In-memory storage
|
||||
games = []
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/footb", 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(**game.dict())
|
||||
games.append(new_game)
|
||||
|
||||
return {
|
||||
"method": "POST",
|
||||
"_verb": "post",
|
||||
"message": "Game created successfully",
|
||||
"game": GameOut.from_orm(new_game)
|
||||
}
|
||||
|
||||
@router.get("/footb")
|
||||
async def get_games():
|
||||
"""Get all active games"""
|
||||
if request.method != "GET":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
active_games = [GameOut.from_orm(game) for game in games if game.is_active]
|
||||
|
||||
return {
|
||||
"method": "GET",
|
||||
"_verb": "get",
|
||||
"games": active_games
|
||||
}
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user