From 612ba8175f21e35d40ef7cb170b67c16d361e3e4 Mon Sep 17 00:00:00 2001 From: fmelihh Date: Sun, 19 May 2024 18:18:06 +0300 Subject: [PATCH] feat: yemeksepeti restaurant value was completed. --- src/recommendation_engine/app/domain/processor.py | 2 +- .../restaurants/values/yemeksepeti/restaurant.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/recommendation_engine/app/domain/processor.py b/src/recommendation_engine/app/domain/processor.py index 1a1534f..73bfb12 100644 --- a/src/recommendation_engine/app/domain/processor.py +++ b/src/recommendation_engine/app/domain/processor.py @@ -44,7 +44,7 @@ def process(self, process_limit: int | None = None) -> T: @staticmethod def _retrieve_json_from_response(response: requests.Response) -> dict | None: try: - return response.json() + return response.json() if isinstance(response, requests.Response) else None except Exception as e: logger.exception( f"given response object cannot be jsonable. url: {response.url}. error details: {e}" diff --git a/src/recommendation_engine/app/domain/restaurants/values/yemeksepeti/restaurant.py b/src/recommendation_engine/app/domain/restaurants/values/yemeksepeti/restaurant.py index e54dc3a..e980dfd 100644 --- a/src/recommendation_engine/app/domain/restaurants/values/yemeksepeti/restaurant.py +++ b/src/recommendation_engine/app/domain/restaurants/values/yemeksepeti/restaurant.py @@ -8,9 +8,9 @@ @dataclass(frozen=True) class YemeksepetiRestaurantValue(RestaurantValue): name: str - rating: int | None + rating: float | int | None url_slug: str - restaurant_id: str + restaurant_id: str | int | float review_number: int | None coordinates: GeoValue | dict | None minimum_pickup_time: float | None @@ -27,7 +27,7 @@ def validate_name(self) -> str: return self.name def validate_rating(self) -> int | None: - if self.rating and not isinstance(self.rating, int): + if self.rating and not isinstance(self.rating, (int, float)): raise ValueError("invalid rating type expected.") return self.rating @@ -37,9 +37,9 @@ def validate_url_slug(self) -> str: return self.url_slug def validate_restaurant_id(self) -> str: - if not isinstance(self.restaurant_id, str): + if not self.restaurant_id: raise ValueError("invalid restaurant_id type expected.") - return self.restaurant_id + return str(self.restaurant_id) def validate_review_number(self) -> int | None: if self.review_number and not isinstance(self.review_number, int):