from fastapi import APIRouter, Depends, status from sqlalchemy.orm import Session from core.database import get_db from schemas.country import CountryCreate, CountrySchema from helpers.country_helpers import create_country, get_country_by_name router = APIRouter() @router.post("/country", status_code=status.HTTP_201_CREATED, response_model=CountrySchema) async def create_new_country( country: CountryCreate, db: Session = Depends(get_db) ): existing_country = get_country_by_name(db, name=country.name) if existing_country: return existing_country new_country = create_country(db, country_data=country) return new_country