feat: add GET endpoint to retrieve all books from database
This commit is contained in:
parent
3741788b29
commit
8e8910498a
@ -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
|
Loading…
x
Reference in New Issue
Block a user