Skip to content

Commit

Permalink
feat: restaurant mapper and orm classes were developed.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed Jul 7, 2024
1 parent 972434d commit df08a2d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/recommendation_engine/app/features/menu/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class MenuModel(ClickhouseBase):
__tablename__ = "comments"
__tablename__ = "menu"

category: str = Column(String)
product_id: str | None = Column(String)
Expand Down
26 changes: 26 additions & 0 deletions src/recommendation_engine/app/features/restaurants/db/models.py
Original file line number Diff line number Diff line change
@@ -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"},
)
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions tests/app/domain/restaurants/test_restaurant_mapper.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit df08a2d

Please sign in to comment.