From 8e8910498a3682f27936ff467d5e58d061daba45 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 29 Apr 2025 18:21:43 +0000 Subject: [PATCH] feat: add GET endpoint to retrieve all books from database --- endpoints/books.get.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/endpoints/books.get.py b/endpoints/books.get.py index e69de29..12c7ec2 100644 --- a/endpoints/books.get.py +++ b/endpoints/books.get.py @@ -0,0 +1,27 @@ +from fastapi import APIRouter, Depends, status +from sqlalchemy.orm import Session +from typing import List +from core.database import get_db +from schemas.book import BookSchema +from helpers.book_helpers import get_all_books + +router = APIRouter() + +@router.get("/books", response_model=List[BookSchema], status_code=status.HTTP_200_OK) +def get_all_books_endpoint( + skip: int = 0, + limit: int = 100, + db: Session = Depends(get_db) +): + """ + Retrieve all books from the database with pagination. + + Parameters: + - skip: Number of records to skip (for pagination) + - limit: Maximum number of records to return (for pagination) + + Returns: + - List of books + """ + books = get_all_books(db=db, skip=skip, limit=limit) + return books \ No newline at end of file