20 lines
544 B
Python
20 lines
544 B
Python
# Entity: Fruit
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from core.database import get_db
|
|
from models.fruit import Fruit
|
|
from schemas.fruit import FruitSchema, FruitCreate
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/db-endpoint", status_code=201, response_model=FruitSchema)
|
|
async def create_fruit(
|
|
fruit_data: FruitCreate,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
new_fruit = Fruit(name=fruit_data.name)
|
|
db.add(new_fruit)
|
|
db.commit()
|
|
db.refresh(new_fruit)
|
|
return new_fruit |