hgjruoi-llirpx/endpoints/sport.post.py
2025-03-24 17:48:40 +00:00

36 lines
836 B
Python

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"]
}
}