20 lines
508 B
Python
20 lines
508 B
Python
# Entity: City
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from core.database import get_db
|
|
from models.city import City
|
|
from schemas.city import CitySchema, CityCreate
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/cities", status_code=201, response_model=CitySchema)
|
|
async def create_city(
|
|
city: CityCreate,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
db_city = City(**city.dict())
|
|
db.add(db_city)
|
|
db.commit()
|
|
db.refresh(db_city)
|
|
return db_city |