From 3a9ccab9a8edf72a32cb6a712f0dcfc934b8a348 Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Tue, 9 Jan 2024 22:51:21 +0000 Subject: [PATCH] Add pages to response --- app/articles/schemas.py | 1 + app/records/schemas.py | 1 + app/schemas/api_response.py | 1 + app/sources/discovery.py | 3 +++ app/sources/website.py | 3 +++ 5 files changed, 9 insertions(+) diff --git a/app/articles/schemas.py b/app/articles/schemas.py index fb24468..b9fabac 100644 --- a/app/articles/schemas.py +++ b/app/articles/schemas.py @@ -19,6 +19,7 @@ class ArticleSearchResults(APIResponse): model_config = ConfigDict(arbitrary_types_allowed=True) count: int = 0 + pages: int = 0 results: list[Article] = [] diff --git a/app/records/schemas.py b/app/records/schemas.py index dbffdf2..97407f5 100644 --- a/app/records/schemas.py +++ b/app/records/schemas.py @@ -16,4 +16,5 @@ class RecordSearchResults(APIResponse): model_config = ConfigDict(arbitrary_types_allowed=True) count: int = 0 + pages: int = 0 results: list[Record] = [] diff --git a/app/schemas/api_response.py b/app/schemas/api_response.py index 1977c45..b3c715e 100644 --- a/app/schemas/api_response.py +++ b/app/schemas/api_response.py @@ -7,6 +7,7 @@ class APIResponse(BaseModel): model_config = ConfigDict(arbitrary_types_allowed=True) count: int = 0 + pages: int = 0 results: list[APIResult] = [] def toJSON(self): diff --git a/app/sources/discovery.py b/app/sources/discovery.py index 318c0a3..090996c 100644 --- a/app/sources/discovery.py +++ b/app/sources/discovery.py @@ -1,3 +1,5 @@ +import math + from app.records.schemas import Record, RecordSearchResults from config import Config @@ -25,4 +27,5 @@ def get_results(self, page: int | None = 1) -> dict: record.title = r["title"] response.results.append(record) response.count = raw_results["count"] + response.pages = math.ceil(response.count / self.results_per_page) return response.toJSON() diff --git a/app/sources/website.py b/app/sources/website.py index 471140e..03bc70b 100644 --- a/app/sources/website.py +++ b/app/sources/website.py @@ -1,3 +1,5 @@ +import math + from app.articles.schemas import Article, ArticleSearchResults from config import Config @@ -44,6 +46,7 @@ def get_results(self, page: int | None = 1) -> dict: article.image = page_details["teaser_image_jpg"] response.results.append(article) response.count = raw_results["meta"]["total_count"] + response.pages = math.ceil(response.count / self.results_per_page) return response.toJSON()