Skip to content

Commit

Permalink
feat: menu dto
Browse files Browse the repository at this point in the history
  • Loading branch information
fmelihh committed Dec 7, 2024
1 parent 615a10e commit f531f51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/recommendation_engine/app/features/menu/services/extraction.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from addict import Dict
from typing import List
from typing import List, Callable

from ..domain.values import GeoValue
from ..domain.values.menu import MenuValue
from ..domain.entity.getir import GetirMenu
from ..dto.menu import MenuDto
from ..mappers.menu import MenuMapper
from ....shared_kernel.extractor import Extractor
from ..domain.entity.yemeksepeti import YemeksepetiMenu
from ....shared_kernel.domain_providers import Providers
Expand All @@ -13,6 +15,15 @@ class MenuExtractorService(Extractor):
def __init__(self, provider_type: Providers, **kwargs):
self.kwargs = Dict(**kwargs)
self.provider = self.initialize_provider(provider_type)
self.mapper_function = self.initialize_mapper_function(provider_type)

def initialize_mapper_function(self, provider_type: Providers) -> Callable:
if provider_type == Providers.YEMEK_SEPETI:
return MenuMapper.yemeksepeti_menu_to_dto
elif provider_type == Providers.GETIR:
return MenuMapper.getir_menu_to_dto
else:
raise ValueError("Provider is not defined.")

def initialize_provider(
self, provider_type: Providers
Expand All @@ -27,5 +38,5 @@ def initialize_provider(
else:
raise ValueError("Provider is not defined.")

def crawl(self) -> List[MenuValue]:
return self.provider.process()
def crawl(self) -> List[MenuDto]:
return [self.mapper_function(element) for element in self.provider.process()]
4 changes: 2 additions & 2 deletions src/recommendation_engine/app/shared_kernel/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from .entity import BaseEntity
from .domain_providers import Providers
from ..features.menu.domain.values import MenuValue
from ..features.menu.dto.menu import MenuDto
from ..features.comments.dto.comment import CommentDto
from ..features.restaurants.dto.restaurants import RestaurantDto

T = TypeVar("T", *[List[RestaurantDto], List[CommentDto], List[MenuValue]])
T = TypeVar("T", *[List[RestaurantDto], List[CommentDto], List[MenuDto]])


class Extractor(ABC):
Expand Down

0 comments on commit f531f51

Please sign in to comment.