Skip to content

Commit

Permalink
feat: fixes misspelling on entities
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed Jul 7, 2024
1 parent 1d9fea6 commit 24f92b7
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ services:
ports:
- "6379:6379"
volumes:
- ./db/redis:/db
- ./data/redis:/data

ch_server:
image: yandex/clickhouse-server
ports:
- "8123:8123"
volumes:
- ./db:/var/lib/clickhouse
- ./data:/var/lib/clickhouse
networks:
- ch_ntw

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _iterate_over_comments(self) -> Generator[dict, None, None]:
if not data:
break

comments = data.get("db")
comments = data.get("data")
next_page_key = data.get("pageKey", "")

if not comments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@


class CommentDto(BaseModel):
reply: str
rating: int
comment: str
comment_id: str
comment_date: datetime.datetime | None = Field(default=None)
replies: list[str]
like_count: int = Field(default=0)
created_at: datetime.datetime | None = Field(default=None)
updated_at: datetime.datetime | None = Field(default=None)
21 changes: 18 additions & 3 deletions src/recommendation_engine/app/features/comments/mappers/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@
class CommentMapper:
@staticmethod
def yemeksepeti_comment_to_dto(value_object: YemeksepetiCommentValue) -> CommentDto:
pass
# TODO: product variation field must be handle.

comment_dto = CommentDto(
rating=value_object.rating.overall_rating,
comment=value_object.comment,
comment_id=value_object.comment_id,
replies=[reply.text for reply in value_object.replies],
like_count=value_object.comment_like_count,
created_at=value_object.created_at,
updated_at=value_object.updated_at,
)
return comment_dto

@staticmethod
def getir_comment_to_dto(value_object: GetirCommentValue) -> CommentDto:
# TODO: getir comment value date text to be uptaded.
# TODO: getir comment value date text to be updated.
comment_dto = CommentDto(
reply=value_object.restaurant_reply,
replies=(
[]
if value_object.restaurant_reply is None
else [value_object.restaurant_reply]
),
rating=value_object.restaurant_rating,
comment=value_object.restaurant_comment,
comment_id=value_object.review_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, restaurant_slug: str):
self.restaurant_slug = restaurant_slug
self.filter_and_search_payload = RequestValue(
url=(
f"https://getir.com/_next/data/EyYN3jDNJWCmlsym2fCyE/tr/yemekPage"
f"https://getir.com/_next/data/7HQpuSyAziWr_FcD2irMg/tr/yemekPage"
f"/restaurants/{self.restaurant_slug}.json?slug={self.restaurant_slug}"
),
method="GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _retrieve_menu_from_api(self) -> list[dict] | None:
if not data:
return []

menu_list = data.get("db", {}).get("menus", [])
menu_list = data.get("data", {}).get("menus", [])
if len(menu_list) > 0:
menu_list = menu_list[0].get("menu_categories")
logger.info(f"Menu with {self.restaurant_id} was crawled.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _iterate_over_restaurants(self) -> Generator[dict, None, None]:
break

restaurants = (
data.get("db", {}).get("restaurantSection", {}).get("restaurants")
data.get("data", {}).get("restaurantSection", {}).get("restaurants")
)

if not restaurants:
Expand Down

Large diffs are not rendered by default.

48 changes: 46 additions & 2 deletions tests/app/domain/comments/test_mapper.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import datetime

from src.recommendation_engine.app.features.comments.dto.comment import CommentDto
from src.recommendation_engine.app.features.comments.mappers.comment import (
CommentMapper,
)
from src.recommendation_engine.app.features.comments.domain.values.getir import (
GetirCommentValue,
)
from src.recommendation_engine.app.features.comments.domain.values.yemeksepeti import (
from src.recommendation_engine.app.features.comments.domain.values.yemeksepeti.comment import (
YemeksepetiCommentValue,
YemeksepetiReplies,
YemekSepetiRating,
ProductVariation,
)


Expand All @@ -23,4 +28,43 @@ def test_getir_mapper():


def test_yemeksepeti_mapper():
pass
yemeksepeti_domain_value = YemeksepetiCommentValue(
comment_id="test",
created_at="2023-07-07T23:00:00",
comment="test",
reviewer_name="test",
reviewer_id="test",
rating=[
{"topic": "overall", "score": 1},
{"topic": "restaurant_food", "score": 1},
{"topic": "rider", "score": 1}
],
comment_like_count=2,
product_variation=[],
replies=[
{
"id": "test",
"text": "text",
"createdAt": "2023-07-07T23:00:00",
"updatedAt": "2023-07-07T23:00:00",
},
{
"id": "test",
"text": "text",
"createdAt": "2023-07-07T23:00:00",
"updatedAt": "2023-07-07T23:00:00",
},
{
"id": "test",
"text": "text",
"createdAt": "2023-07-07T23:00:00",
"updatedAt": "2023-07-07T23:00:00",
},
],
updated_at="2023-07-07T23:00:00",
)

res = CommentMapper.yemeksepeti_comment_to_dto(
value_object=yemeksepeti_domain_value
)
assert isinstance(res, CommentDto)

0 comments on commit 24f92b7

Please sign in to comment.