-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: menu mapper and models were developed.
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
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 |
---|---|---|
@@ -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"}, | ||
) |
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
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 |
---|---|---|
@@ -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
31
src/recommendation_engine/app/features/menu/mappers/menu.py
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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) |