diff --git a/src/recommendation_engine/app/features/menu/db/models.py b/src/recommendation_engine/app/features/menu/db/models.py index a7826d3..9adf820 100644 --- a/src/recommendation_engine/app/features/menu/db/models.py +++ b/src/recommendation_engine/app/features/menu/db/models.py @@ -5,7 +5,7 @@ class MenuModel(ClickhouseBase): - __tablename__ = "comments" + __tablename__ = "menu" category: str = Column(String) product_id: str | None = Column(String) diff --git a/src/recommendation_engine/app/features/restaurants/db/models.py b/src/recommendation_engine/app/features/restaurants/db/models.py index e69de29..4b2b8fd 100644 --- a/src/recommendation_engine/app/features/restaurants/db/models.py +++ b/src/recommendation_engine/app/features/restaurants/db/models.py @@ -0,0 +1,26 @@ +from clickhouse_sqlalchemy import engines +from sqlalchemy import Column, String, Float, Integer + +from ....core.database.clickhouse import ClickhouseBase + + +class RestaurantModel(ClickhouseBase): + __tablename__ = "restaurant" + + name: str = Column(String) + rating: float = Column(Float) + restaurant_id: str = Column(String) + delivery_fee: float = Column(Float) + restaurant_slug: str = Column(String) + delivery_time: float = Column(Float) + delivery_fee_currency: str = Column(String) + review_number: int = Column(Integer) + image_url: str | None = Column(String) + order_amount: float | None = Column(Float, nullable=True) + order_amount_currency: str | None = Column(String, nullable=True) + loyalty_percentage_amount: float | None = Column(Float, nullable=True) + + __table_args__ = ( + engines.MergeTree(order_by=["restaurant_id"]), + {"schema": "default"}, + ) diff --git a/src/recommendation_engine/app/features/restaurants/domain/values/getir/restaurant.py b/src/recommendation_engine/app/features/restaurants/domain/values/getir/restaurant.py index 193f448..89dceff 100644 --- a/src/recommendation_engine/app/features/restaurants/domain/values/getir/restaurant.py +++ b/src/recommendation_engine/app/features/restaurants/domain/values/getir/restaurant.py @@ -14,11 +14,11 @@ class GetirRestaurantValue(RestaurantValue): slug: str | None = None image_url: str | None = None rating_point: float | None = None - rating_count: RatingCount | None = None - min_basket_size: Price | None = None - restaurant_min_basket_size: Price | None = None - estimated_delivery_time: DeliveryTime | None = None - delivery_fee: Price | None = None + rating_count: RatingCount | str | None = None + min_basket_size: Price | str | None = None + restaurant_min_basket_size: Price | str | None = None + estimated_delivery_time: DeliveryTime | dict | None = None + delivery_fee: Price | str | None = None def validate_id(self) -> str: if not isinstance(self.id, str): diff --git a/src/recommendation_engine/app/features/restaurants/dto/restaurants.py b/src/recommendation_engine/app/features/restaurants/dto/restaurants.py index e69de29..4bbc1e3 100644 --- a/src/recommendation_engine/app/features/restaurants/dto/restaurants.py +++ b/src/recommendation_engine/app/features/restaurants/dto/restaurants.py @@ -0,0 +1,16 @@ +from pydantic import BaseModel, Field + + +class RestaurantDto(BaseModel): + name: str + rating: float + restaurant_id: str + delivery_fee: float + restaurant_slug: str + delivery_time: float + delivery_fee_currency: str + review_number: int = Field(default=0) + image_url: str | None = Field(default=None) + order_amount: float | None = Field(default=None) + order_amount_currency: str | None = Field(default=None) + loyalty_percentage_amount: float | None = Field(default=None) diff --git a/src/recommendation_engine/app/features/restaurants/mappers/restaurants.py b/src/recommendation_engine/app/features/restaurants/mappers/restaurants.py index e69de29..77b0b96 100644 --- a/src/recommendation_engine/app/features/restaurants/mappers/restaurants.py +++ b/src/recommendation_engine/app/features/restaurants/mappers/restaurants.py @@ -0,0 +1,40 @@ +from ..dto.restaurants import RestaurantDto +from ..domain.entity.getir import GetirRestaurantValue +from ..domain.entity.yemek_sepeti import YemeksepetiRestaurantValue + + +class RestaurantMapper: + @staticmethod + def yemeksepeti_restaurant_to_dto( + value_object: YemeksepetiRestaurantValue, + ) -> RestaurantDto: + restaurant_dto = RestaurantDto( + restaurant_slug=value_object.url_slug, + restaurant_id=value_object.restaurant_id, + name=value_object.name, + rating=value_object.rating, + image_url=None, + review_number=value_object.review_number, + order_amount=value_object.minimum_order_amount.amount, + order_amount_currency=value_object.minimum_order_amount.currency, + delivery_fee=value_object.minimum_delivery_fee.amount, + delivery_fee_currency=value_object.minimum_delivery_fee.currency, + delivery_time=value_object.minimum_delivery_time, + loyalty_percentage_amount=value_object.loyalty_percentage_amount, + ) + return restaurant_dto + + @staticmethod + def getir_restaurant_to_dto(value_object: GetirRestaurantValue) -> RestaurantDto: + restaurant_dto = RestaurantDto( + restaurant_slug=value_object.slug, + restaurant_id=value_object.id, + name=value_object.name, + rating=value_object.rating_point, + image_url=value_object.image_url, + review_number=value_object.rating_count.count, + delivery_fee=value_object.delivery_fee.amount, + delivery_fee_currency=value_object.delivery_fee.currency, + delivery_time=value_object.estimated_delivery_time.le, + ) + return restaurant_dto diff --git a/tests/app/domain/restaurants/test_restaurant_mapper.py b/tests/app/domain/restaurants/test_restaurant_mapper.py new file mode 100644 index 0000000..9f0446e --- /dev/null +++ b/tests/app/domain/restaurants/test_restaurant_mapper.py @@ -0,0 +1,49 @@ +from src.recommendation_engine.app.features.restaurants.dto.restaurants import ( + RestaurantDto, +) +from src.recommendation_engine.app.features.restaurants.mappers.restaurants import ( + RestaurantMapper, +) +from src.recommendation_engine.app.features.restaurants.domain.values.getir import ( + GetirRestaurantValue, +) +from src.recommendation_engine.app.features.restaurants.domain.values.yemeksepeti import ( + YemeksepetiRestaurantValue +) + + +def test_getir_mapper(): + getir_domain_value = GetirRestaurantValue( + id="a", + name="a", + slug="a", + image_url="https://localhost.com", + rating_point=0.0, + rating_count="31", + min_basket_size="31", + restaurant_min_basket_size="31", + estimated_delivery_time={"suffix": "a", "value": "2-3"}, + delivery_fee="1", + ) + res = RestaurantMapper.getir_restaurant_to_dto(value_object=getir_domain_value) + assert isinstance(res, RestaurantDto) + + +def test_yemeksepeti_mapper(): + yemeksepeti_domain_value = YemeksepetiRestaurantValue( + name="a", + rating=3, + url_slug="a", + restaurant_id="a", + review_number=1, + coordinates={"lat": 1.1, "lon": 1.1}, + minimum_pickup_time=1, + minimum_order_amount=1, + minimum_delivery_fee=1, + minimum_delivery_time=1, + original_delivery_fee=1, + loyalty_percentage_amount=1 + ) + + res = RestaurantMapper.yemeksepeti_restaurant_to_dto(value_object=yemeksepeti_domain_value) + assert isinstance(res, RestaurantDto)