diff --git a/Pipfile b/Pipfile index 64cafca..df327d3 100644 --- a/Pipfile +++ b/Pipfile @@ -22,6 +22,7 @@ line-bot-sdk = "*" flask = "*" pyzbar = "*" pillow = "*" +fastapi-pagination = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 41fefba..6c33305 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "66036465c645ba44b441f1f5419bf1796063c319b804996c46cc9b1f1d6e46f3" + "sha256": "e2cde36e7fdee07e836218768b40acd7044aa61c90976cb342dfa229ff42aff7" }, "pipfile-spec": 6, "requires": { @@ -126,14 +126,6 @@ "markers": "python_version >= '3.6'", "version": "==4.0.2" }, - "atomicwrites": { - "hashes": [ - "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197", - "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a" - ], - "markers": "sys_platform == 'win32'", - "version": "==1.4.0" - }, "attrs": { "hashes": [ "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4", @@ -243,20 +235,12 @@ "markers": "python_version >= '3.6'", "version": "==8.0.4" }, - "colorama": { - "hashes": [ - "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b", - "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2" - ], - "markers": "sys_platform == 'win32'", - "version": "==0.4.4" - }, "dnspython": { "hashes": [ "sha256:0f7569a4a6ff151958b64304071d370daa3243d15941a7beedf0c9fe5105603e", "sha256:a851e51367fb93e9e1361732c1d60dab63eff98712e503ea7d92e6eccb109b4f" ], - "markers": "python_version >= '3.6' and python_version < '4.0'", + "markers": "python_version >= '3.6' and python_version < '4'", "version": "==2.2.1" }, "email-validator": { @@ -274,6 +258,14 @@ "index": "pypi", "version": "==0.75.0" }, + "fastapi-pagination": { + "hashes": [ + "sha256:401b0fdbc0e12e7b178c7f37709918a93df44827d3de75fb7d85d6c4465e77b0", + "sha256:ef84b01f364e5eb4dec0c59068c02e83c4a04319659354297680122592c9b884" + ], + "index": "pypi", + "version": "==0.9.1" + }, "flake8": { "hashes": [ "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d", @@ -895,7 +887,7 @@ "sha256:000ca7f471a233c2251c6c7023ee85305721bfdf18621ebff4fd17a8653427ed", "sha256:0e7c33d9a63e7ddfcb86780aac87befc2fbddf46c58dbb487e0855f7ceec283c" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "version": "==1.26.8" }, "uvicorn": { diff --git a/api.py b/api.py index de16f5c..3fe17ae 100644 --- a/api.py +++ b/api.py @@ -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( @@ -18,3 +19,5 @@ ) app.include_router(router) +add_pagination(app) + diff --git a/routers/api.py b/routers/api.py index 1a33b13..99ac3c3 100644 --- a/routers/api.py +++ b/routers/api.py @@ -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)