feat: Generated endpoint endpoints/country.post.py via AI
This commit is contained in:
parent
160e9ee57e
commit
8794f5aec9
@ -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
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user