Add POST endpoint for /book
This commit is contained in:
parent
3f8a835dfc
commit
5154304cb5
@ -0,0 +1,20 @@
|
||||
# Entity: Book
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_db
|
||||
from models.book import Book
|
||||
from schemas.book import BookSchema, BookCreate
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/book", status_code=201, response_model=BookSchema)
|
||||
async def create_book(
|
||||
book: BookCreate,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
new_book = Book(**book.dict())
|
||||
db.add(new_book)
|
||||
db.commit()
|
||||
db.refresh(new_book)
|
||||
return new_book
|
Loading…
x
Reference in New Issue
Block a user