Add GET endpoint for /library

This commit is contained in:
Backend IM Bot 2025-03-25 23:19:08 +00:00
parent f9ccbec208
commit ae37c5b369

View File

@ -0,0 +1,17 @@
# Entity: Book
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from typing import List
from core.database import get_db
from core.models.book import Book
from core.models.author import Author
from core.schemas.book import BookSchema
router = APIRouter()
@router.get("/library", response_model=List[BookSchema], status_code=200)
async def get_books_by_authors(
db: Session = Depends(get_db)
):
books = db.query(Book).join(Author).all()
return books