Skip to content

Commit

Permalink
feat: menu mapper and models were developed.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed Jul 7, 2024
1 parent c3f5eab commit dbe6805
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/recommendation_engine/app/features/menu/db/models.py
Original file line number Diff line number Diff line change
@@ -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"},
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/recommendation_engine/app/features/menu/dto/menu.py
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions src/recommendation_engine/app/features/menu/mappers/menu.py
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions tests/app/domain/menu/test_mapper.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit dbe6805

Please sign in to comment.