yusuf-9fqifw/endpoints/books.post.py
2025-03-29 07:58:22 +00:00

17 lines
510 B
Python

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