Update code in endpoints/books.get.py
This commit is contained in:
parent
6ffa49dbe1
commit
cacb39b3bb
@ -1,17 +1,30 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, status
|
||||||
from sqlalchemy.orm import Session
|
|
||||||
from typing import List
|
from typing import List
|
||||||
from core.database import get_db
|
|
||||||
from models.book import Book
|
|
||||||
from schemas.book import BookSchema
|
from schemas.book import BookSchema
|
||||||
from helpers.book_helpers import get_all_books
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/books", status_code=200, response_model=List[BookSchema])
|
@router.get("/books", status_code=status.HTTP_200_OK, response_model=List[BookSchema])
|
||||||
async def get_books(
|
async def get_books():
|
||||||
db: Session = Depends(get_db)
|
|
||||||
):
|
|
||||||
"""Get all books"""
|
"""Get all books"""
|
||||||
books = get_all_books(db)
|
books = [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"title": "The Great Gatsby",
|
||||||
|
"author": "F. Scott Fitzgerald",
|
||||||
|
"year": 1925
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"title": "To Kill a Mockingbird",
|
||||||
|
"author": "Harper Lee",
|
||||||
|
"year": 1960
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"title": "1984",
|
||||||
|
"author": "George Orwell",
|
||||||
|
"year": 1949
|
||||||
|
}
|
||||||
|
]
|
||||||
return books
|
return books
|
Loading…
x
Reference in New Issue
Block a user