Add POST endpoint for /db-endpoint
This commit is contained in:
parent
24d1cbe1b2
commit
3e353bba09
@ -0,0 +1,20 @@
|
|||||||
|
# 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
|
Loading…
x
Reference in New Issue
Block a user