-
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: restaurant mapper and orm classes were developed.
- Loading branch information
Showing
6 changed files
with
137 additions
and
6 deletions.
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
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,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"}, | ||
) |
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,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) |
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,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 |
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,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) |