Update code in endpoints/sport.post.py
This commit is contained in:
parent
9b8ad04e51
commit
35c4660a9b
@ -0,0 +1,36 @@
|
|||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
# Schema
|
||||||
|
class Sport(BaseModel):
|
||||||
|
name: str
|
||||||
|
category: str
|
||||||
|
team_based: bool
|
||||||
|
indoor: bool
|
||||||
|
|
||||||
|
# Storage
|
||||||
|
sports = [] # In-memory storage
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/sport")
|
||||||
|
async def create_sport(
|
||||||
|
sport: Sport
|
||||||
|
):
|
||||||
|
"""Create new sport entry"""
|
||||||
|
if any(s["name"] == sport.name for s in sports):
|
||||||
|
raise HTTPException(status_code=400, detail="Sport already exists")
|
||||||
|
|
||||||
|
sport_dict = sport.dict()
|
||||||
|
sports.append(sport_dict)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "Sport created successfully",
|
||||||
|
"sport": sport_dict,
|
||||||
|
"total_sports": len(sports),
|
||||||
|
"features": {
|
||||||
|
"categories": ["team", "individual"],
|
||||||
|
"environments": ["indoor", "outdoor"]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user