Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Add pages to response
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jan 9, 2024
1 parent eba6c55 commit 3a9ccab
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/articles/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ArticleSearchResults(APIResponse):
model_config = ConfigDict(arbitrary_types_allowed=True)

count: int = 0
pages: int = 0
results: list[Article] = []


Expand Down
1 change: 1 addition & 0 deletions app/records/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ class RecordSearchResults(APIResponse):
model_config = ConfigDict(arbitrary_types_allowed=True)

count: int = 0
pages: int = 0
results: list[Record] = []
1 change: 1 addition & 0 deletions app/schemas/api_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions app/sources/discovery.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

from app.records.schemas import Record, RecordSearchResults
from config import Config

Expand Down Expand Up @@ -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()
3 changes: 3 additions & 0 deletions app/sources/website.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

from app.articles.schemas import Article, ArticleSearchResults
from config import Config

Expand Down Expand Up @@ -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()


Expand Down

0 comments on commit 3a9ccab

Please # to comment.