diff --git a/src/recommendation_engine/app/features/menu/db/models.py b/src/recommendation_engine/app/features/menu/db/models.py new file mode 100644 index 0000000..a7826d3 --- /dev/null +++ b/src/recommendation_engine/app/features/menu/db/models.py @@ -0,0 +1,21 @@ +from clickhouse_sqlalchemy import engines +from sqlalchemy import Column, String, Float + +from ....core.database.clickhouse import ClickhouseBase + + +class MenuModel(ClickhouseBase): + __tablename__ = "comments" + + category: str = Column(String) + product_id: str | None = Column(String) + name: str = Column(String) + description: str = Column(String) + image_url: str = Column(String) + price: float = Column(Float) + price_currency: str = Column(String) + + __table_args__ = ( + engines.MergeTree(order_by=["product_id"]), + {"schema": "default"}, + ) diff --git a/src/recommendation_engine/app/features/menu/domain/values/getir/menu.py b/src/recommendation_engine/app/features/menu/domain/values/getir/menu.py index 6a9404c..7ad2d5d 100644 --- a/src/recommendation_engine/app/features/menu/domain/values/getir/menu.py +++ b/src/recommendation_engine/app/features/menu/domain/values/getir/menu.py @@ -10,7 +10,7 @@ class GetirMenuValue(MenuValue): category: str product_id: str name: str - price: Price + price: Price | str description: str image_url: str | None full_screen_image_url: str | None diff --git a/src/recommendation_engine/app/features/menu/dto/menu.py b/src/recommendation_engine/app/features/menu/dto/menu.py new file mode 100644 index 0000000..199af10 --- /dev/null +++ b/src/recommendation_engine/app/features/menu/dto/menu.py @@ -0,0 +1,11 @@ +from pydantic import BaseModel, Field + + +class MenuDto(BaseModel): + category: str + product_id: str | None = Field(None) + name: str + description: str + image_url: str + price: float + price_currency: str diff --git a/src/recommendation_engine/app/features/menu/mappers/menu.py b/src/recommendation_engine/app/features/menu/mappers/menu.py new file mode 100644 index 0000000..e054519 --- /dev/null +++ b/src/recommendation_engine/app/features/menu/mappers/menu.py @@ -0,0 +1,31 @@ +from ..dto.menu import MenuDto +from ..domain.entity.getir import GetirMenuValue +from ..domain.entity.yemeksepeti import YemeksepetiMenuValue + + +class MenuMapper: + @staticmethod + def yemeksepeti_menu_to_dto(value_object: YemeksepetiMenuValue) -> MenuDto: + menu_dto = MenuDto( + category=value_object.category, + product_id=value_object.product_id, + name=value_object.name, + description=value_object.description, + image_url=value_object.image_url, + price=value_object.price.amount, + price_currency=value_object.price.currency, + ) + return menu_dto + + @staticmethod + def getir_menu_to_dto(value_object: GetirMenuValue) -> MenuDto: + menu_dto = MenuDto( + category=value_object.category, + product_id=value_object.product_id, + name=value_object.name, + description=value_object.description, + image_url=value_object.image_url, + price=value_object.price.amount, + price_currency=value_object.price.currency, + ) + return menu_dto diff --git a/tests/app/domain/menu/test_mapper.py b/tests/app/domain/menu/test_mapper.py new file mode 100644 index 0000000..e542266 --- /dev/null +++ b/tests/app/domain/menu/test_mapper.py @@ -0,0 +1,39 @@ +from src.recommendation_engine.app.features.menu.dto.menu import MenuDto +from src.recommendation_engine.app.features.menu.mappers.menu import ( + MenuMapper, +) +from src.recommendation_engine.app.features.menu.domain.values.getir import ( + GetirMenuValue, +) +from src.recommendation_engine.app.features.menu.domain.values.yemeksepeti.menu import ( + YemeksepetiMenuValue, +) + + +def test_getir_mapper(): + getir_domain_value = GetirMenuValue( + category="a", + product_id="a", + name="a", + price="31", + description="a", + image_url="https://a.com", + full_screen_image_url="https://a.com", + is_available=False, + ) + res = MenuMapper.getir_menu_to_dto(value_object=getir_domain_value) + assert isinstance(res, MenuDto) + + +def test_yemeksepeti_mapper(): + yemeksepeti_domain_value = YemeksepetiMenuValue( + category="a", + product_id="a", + name="a", + price=3, + description="a", + image_url="https://a.com", + ) + + res = MenuMapper.yemeksepeti_menu_to_dto(value_object=yemeksepeti_domain_value) + assert isinstance(res, MenuDto)