From 2690636d3e7dce3ab4262e67c216bd4eafc9072a Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Mon, 3 Apr 2023 14:29:29 -0400 Subject: [PATCH] Add pageSize to pagination format --- backend/btrixcloud/colls.py | 2 +- backend/btrixcloud/crawlconfigs.py | 8 ++++---- backend/btrixcloud/crawls.py | 4 ++-- backend/btrixcloud/orgs.py | 4 ++-- backend/btrixcloud/pagination.py | 9 +++++++-- backend/btrixcloud/profiles.py | 2 +- backend/btrixcloud/users.py | 2 +- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/backend/btrixcloud/colls.py b/backend/btrixcloud/colls.py index edeb8c1e10..f26d6e25e1 100644 --- a/backend/btrixcloud/colls.py +++ b/backend/btrixcloud/colls.py @@ -191,7 +191,7 @@ async def list_collection_all( collections, total = await colls.list_collections( org.id, page_size=pageSize, page=page ) - return paginated_format(collections, total, page) + return paginated_format(collections, total, page, pageSize) @router.get("/$all") async def get_collection_all(org: Organization = Depends(org_viewer_dep)): diff --git a/backend/btrixcloud/crawlconfigs.py b/backend/btrixcloud/crawlconfigs.py index 4e1bb568f1..87edc97c64 100644 --- a/backend/btrixcloud/crawlconfigs.py +++ b/backend/btrixcloud/crawlconfigs.py @@ -933,7 +933,7 @@ async def get_crawl_configs( sort_by=sortBy, sort_direction=sortDirection, ) - return paginated_format(crawl_configs, total, page) + return paginated_format(crawl_configs, total, page, pageSize) @router.get("/tags") async def get_crawl_config_tags(org: Organization = Depends(org_viewer_dep)): @@ -954,12 +954,12 @@ async def get_crawl_config(cid: str, org: Organization = Depends(org_viewer_dep) dependencies=[Depends(org_viewer_dep)], ) async def get_crawl_config_revisions( - cid: str, page_size: int = DEFAULT_PAGE_SIZE, page: int = 1 + cid: str, pageSize: int = DEFAULT_PAGE_SIZE, page: int = 1 ): revisions, total = await ops.get_crawl_config_revs( - uuid.UUID(cid), page_size=page_size, page=page + uuid.UUID(cid), page_size=pageSize, page=page ) - return paginated_format(revisions, total, page) + return paginated_format(revisions, total, page, pageSize) @router.post("/") async def add_crawl_config( diff --git a/backend/btrixcloud/crawls.py b/backend/btrixcloud/crawls.py index ca3f3d93d0..18d737b22f 100644 --- a/backend/btrixcloud/crawls.py +++ b/backend/btrixcloud/crawls.py @@ -810,7 +810,7 @@ async def list_crawls_admin( sort_by=sortBy, sort_direction=sortDirection, ) - return paginated_format(crawls, total, page) + return paginated_format(crawls, total, page, pageSize) @app.get("/orgs/{oid}/crawls", tags=["crawls"]) async def list_crawls( @@ -853,7 +853,7 @@ async def list_crawls( sort_by=sortBy, sort_direction=sortDirection, ) - return paginated_format(crawls, total, page) + return paginated_format(crawls, total, page, pageSize) @app.post( "/orgs/{oid}/crawls/{crawl_id}/cancel", diff --git a/backend/btrixcloud/orgs.py b/backend/btrixcloud/orgs.py index c9b8ef5200..1337f937c7 100644 --- a/backend/btrixcloud/orgs.py +++ b/backend/btrixcloud/orgs.py @@ -420,7 +420,7 @@ async def get_orgs( serialized_results = [ await res.serialize_for_user(user, user_manager) for res in results ] - return paginated_format(serialized_results, total, page) + return paginated_format(serialized_results, total, page, pageSize) @app.post("/orgs/create", tags=["organizations"]) async def create_org( @@ -517,7 +517,7 @@ async def get_pending_org_invites( pending_invites, total = await user_manager.invites.get_pending_invites( org, page_size=pageSize, page=page ) - return paginated_format(pending_invites, total, page) + return paginated_format(pending_invites, total, page, pageSize) @router.post("/invites/delete", tags=["invites"]) async def delete_invite( diff --git a/backend/btrixcloud/pagination.py b/backend/btrixcloud/pagination.py index 345557b5bd..6f2b6756cd 100644 --- a/backend/btrixcloud/pagination.py +++ b/backend/btrixcloud/pagination.py @@ -5,6 +5,11 @@ DEFAULT_PAGE_SIZE = 1_000 -def paginated_format(items: Optional[List[Any]], total: int, page: int = 1): +def paginated_format( + items: Optional[List[Any]], + total: int, + page: int = 1, + page_size: int = DEFAULT_PAGE_SIZE, +): """Return items in paged format.""" - return {"items": items, "total": total, "page": page} + return {"items": items, "total": total, "page": page, "pageSize": page_size} diff --git a/backend/btrixcloud/profiles.py b/backend/btrixcloud/profiles.py index d4a4ab621d..02ee821380 100644 --- a/backend/btrixcloud/profiles.py +++ b/backend/btrixcloud/profiles.py @@ -421,7 +421,7 @@ async def list_profiles( profiles, total = await ops.list_profiles( org, userid, page_size=pageSize, page=page ) - return paginated_format(profiles, total, page) + return paginated_format(profiles, total, page, pageSize) @router.post("", response_model=Profile) async def commit_browser_to_new( diff --git a/backend/btrixcloud/users.py b/backend/btrixcloud/users.py index 276d6231b3..e827d01e41 100644 --- a/backend/btrixcloud/users.py +++ b/backend/btrixcloud/users.py @@ -483,7 +483,7 @@ async def get_pending_invites( pending_invites, total = await user_manager.invites.get_pending_invites( page_size=pageSize, page=page ) - return paginated_format(pending_invites, total, page) + return paginated_format(pending_invites, total, page, pageSize) app.include_router(users_router, prefix="/users", tags=["users"])