feat: Add POST /books endpoint
This commit is contained in:
parent
11c16ca013
commit
f987431b99
@ -0,0 +1,18 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
from models.book import Book
|
||||||
|
from schemas.book import BookSchema, BookCreate
|
||||||
|
from helpers.book_helpers import create_book
|
||||||
|
from core.database import get_db
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("/books", status_code=status.HTTP_201_CREATED, response_model=BookSchema)
|
||||||
|
async def create_new_book(
|
||||||
|
book: BookCreate,
|
||||||
|
db: Session = Depends(get_db)
|
||||||
|
):
|
||||||
|
new_book = create_book(db=db, book=book)
|
||||||
|
if not new_book:
|
||||||
|
raise HTTPException(status_code=400, detail="Book could not be created")
|
||||||
|
return new_book
|
Loading…
x
Reference in New Issue
Block a user