18 lines
543 B
Python
18 lines
543 B
Python
from fastapi import APIRouter, HTTPException, status
|
|
from pydantic import BaseModel
|
|
from .services import create_country
|
|
|
|
router = APIRouter()
|
|
|
|
class CountryData(BaseModel):
|
|
name: str
|
|
color: str
|
|
|
|
@router.post("/create-country", status_code=status.HTTP_201_CREATED)
|
|
async def create_new_country(country_data: CountryData):
|
|
"""Create a new country"""
|
|
try:
|
|
created_country = create_country(country_data)
|
|
return created_country
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e)) |