From 8794f5aec972aad9041b59d6c645e7f35ca2d1dc Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Mon, 14 Apr 2025 20:23:48 +0000 Subject: [PATCH] feat: Generated endpoint endpoints/country.post.py via AI --- endpoints/country.post.py | 18 ++++++++++++++++++ schemas/country.py | 7 +++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/endpoints/country.post.py b/endpoints/country.post.py index e69de29..73e74e5 100644 --- a/endpoints/country.post.py +++ b/endpoints/country.post.py @@ -0,0 +1,18 @@ +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 \ No newline at end of file diff --git a/schemas/country.py b/schemas/country.py index 29f8678..7fb1e14 100644 --- a/schemas/country.py +++ b/schemas/country.py @@ -1,7 +1,6 @@ import enum from pydantic import BaseModel, Field from typing import Optional -from datetime import datetime import uuid class Continent(enum.Enum): @@ -17,7 +16,7 @@ class CountryBase(BaseModel): name: str = Field(..., description="Country name") latitude: float = Field(..., description="Country latitude") longitude: float = Field(..., description="Country longitude") - continent: Optional[Continent] = Field(None, description="Country continent") + continent: Continent = Field(..., description="Country continent") class CountryCreate(CountryBase): pass @@ -30,8 +29,8 @@ class CountryUpdate(CountryBase): class CountrySchema(CountryBase): id: uuid.UUID - created_at: datetime - updated_at: datetime + created_at: float + updated_at: float class Config: orm_mode = True \ No newline at end of file