-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let pydantic parse json of ReviewsSummary
somehow it was forgotten to add this change in 57dbab6
- Loading branch information
Showing
1 changed file
with
1 addition
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,10 @@ | ||
from api.models.ReviewsSummary import ReviewsSummary | ||
|
||
|
||
def _avoid_none(value: float | int | None) -> float | int: | ||
return value or 0 | ||
|
||
|
||
class ReviewsSummaryParser: | ||
|
||
@staticmethod | ||
def parse(reviews_info: dict) -> ReviewsSummary | None: | ||
if not reviews_info: | ||
return None | ||
|
||
return ReviewsSummary( | ||
positive=_avoid_none(reviews_info["positive"]), | ||
negative=_avoid_none(reviews_info["negative"]), | ||
score=_avoid_none(reviews_info["score"]), | ||
average_score=_avoid_none(reviews_info["averageScore"]), | ||
num_reviews=_avoid_none(reviews_info["reviews"]), | ||
lower_bound=_avoid_none(reviews_info["lowerBound"]), | ||
) | ||
return ReviewsSummary(**reviews_info) |