Update code in endpoints/books.post.py

This commit is contained in:
Backend IM Bot 2025-03-29 07:58:22 +00:00
parent c21eba0020
commit 6143597a22

View File

@ -0,0 +1,17 @@
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
from helpers.book_helpers import create_book
router = APIRouter()
@router.post("/books", status_code=201, response_model=BookSchema)
async def add_book(
book: BookCreate,
db: Session = Depends(get_db)
):
"""Add a new book"""
new_book = create_book(db=db, book=book)
return new_book