Skip to content

Commit

Permalink
[modify] pagenateの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
fabMichelangelo committed Mar 15, 2022
1 parent f832675 commit 4a9cdf3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ line-bot-sdk = "*"
flask = "*"
pyzbar = "*"
pillow = "*"
fastapi-pagination = "*"

[dev-packages]

Expand Down
30 changes: 11 additions & 19 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from routers.api import router
from db.main import engine
from db.models import Base
from fastapi_pagination import Page, add_pagination, paginate

Base.metadata.create_all(bind=engine)
app = FastAPI(
Expand All @@ -18,3 +19,5 @@
)

app.include_router(router)
add_pagination(app)

7 changes: 5 additions & 2 deletions routers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from db.main import get_db
from cruds.api import get_books_by_id
from schemas.api import Book
from fastapi_pagination import paginate
from fastapi_pagination import Page, add_pagination, paginate


router = APIRouter()

@router.get('/books/{user_id}', response_model=List[Book])
@router.get('/books/{user_id}', response_model=Page[Book])
async def books(user_id: str, db: Session = Depends(get_db)):
books = get_books_by_id(db, user_id)
return books
return paginate(books)

0 comments on commit 4a9cdf3

Please sign in to comment.