service/repo.submenu typehint

develop
Сергей Ванюшкин 2024-02-04 17:49:55 +03:00
parent 35659529b4
commit 2754b82b5d
1 changed files with 23 additions and 7 deletions

View File

@ -33,24 +33,40 @@ class SubmenuService:
submenus.append(submenu)
return submenus
async def create_submenu(self, menu_id: UUID, submenu_data: MenuBase):
async def create_submenu(
self, menu_id: UUID, submenu_data: MenuBase
) -> SubMenuRead:
data = await self.submenu_repo.create_submenu_item(
menu_id,
submenu_data,
)
return data
menu = data.__dict__
menu = {k: v for k, v in menu.items() if not k.startswith('_')}
menu['dishes_count'] = len(menu.pop('dishes'))
menu = SubMenuRead(**menu)
return menu
async def read_menu(self, menu_id: UUID, submenu_id: UUID):
async def read_menu(self, menu_id: UUID, submenu_id: UUID) -> SubMenuRead | None:
data = await self.submenu_repo.get_submenu_item(menu_id, submenu_id)
return data
if data is None:
return None
menu = data.__dict__
menu = {k: v for k, v in menu.items() if not k.startswith('_')}
menu['dishes_count'] = len(menu.pop('dishes'))
menu = SubMenuRead(**menu)
return menu
async def update_submenu(
self, menu_id: UUID, submenu_id: UUID, submenu_data: MenuBase
):
) -> SubMenuRead:
data = await self.submenu_repo.update_submenu_item(
menu_id, submenu_id, submenu_data
)
return data
menu = data.__dict__
menu = {k: v for k, v in menu.items() if not k.startswith('_')}
menu['dishes_count'] = len(menu.pop('dishes'))
menu = SubMenuRead(**menu)
return menu
async def del_menu(self, menu_id: UUID, submenu_id: UUID):
async def del_menu(self, menu_id: UUID, submenu_id: UUID) -> int:
return await self.submenu_repo.delete_submenu_item(menu_id, submenu_id)