From 7d4c4d9be37c3b0c9b1739415326f2683b46f690 Mon Sep 17 00:00:00 2001 From: pi3c Date: Tue, 6 Feb 2024 15:50:02 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20typehint=20=D0=B2=20serv/repos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastfood/repository/dish.py | 5 ++--- fastfood/repository/menu.py | 6 ++---- fastfood/repository/submenu.py | 7 ++----- fastfood/service/dish.py | 6 ++---- fastfood/service/menu.py | 5 ++--- fastfood/service/submenu.py | 5 ++--- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/fastfood/repository/dish.py b/fastfood/repository/dish.py index 7935d49..b7cf10b 100644 --- a/fastfood/repository/dish.py +++ b/fastfood/repository/dish.py @@ -10,7 +10,7 @@ from fastfood.schemas import Dish_db class DishRepository: - def __init__(self, session: AsyncSession = Depends(get_async_session)): + def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None: self.db = session async def get_dishes(self, menu_id: UUID, submenu_id: UUID) -> list[Dish]: @@ -62,8 +62,7 @@ class DishRepository: menu_id: UUID, submenu_id: UUID, dish_id: UUID, - ) -> int: + ) -> None: query = delete(Dish).where(Dish.id == dish_id) await self.db.execute(query) await self.db.commit() - return 200 diff --git a/fastfood/repository/menu.py b/fastfood/repository/menu.py index a7937a8..3e18964 100644 --- a/fastfood/repository/menu.py +++ b/fastfood/repository/menu.py @@ -11,7 +11,7 @@ from fastfood.models import Dish, Menu, SubMenu class MenuRepository: - def __init__(self, session: AsyncSession = Depends(get_async_session)): + def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None: self.db = session async def get_menus(self) -> list[Menu]: @@ -44,8 +44,6 @@ class MenuRepository: ) menu = await self.db.execute(query) menu = menu.scalars().one_or_none() - if menu is None: - return None return menu async def update_menu_item( @@ -60,7 +58,7 @@ class MenuRepository: updated_menu = await self.db.execute(qr) return updated_menu.scalar_one() - async def delete_menu_item(self, menu_id: UUID): + async def delete_menu_item(self, menu_id: UUID) -> None: query = delete(Menu).where(Menu.id == menu_id) await self.db.execute(query) await self.db.commit() diff --git a/fastfood/repository/submenu.py b/fastfood/repository/submenu.py index 523ad89..5115930 100644 --- a/fastfood/repository/submenu.py +++ b/fastfood/repository/submenu.py @@ -11,7 +11,7 @@ from fastfood.schemas import MenuBase class SubMenuRepository: - def __init__(self, session: AsyncSession = Depends(get_async_session)): + def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None: self.db = session async def get_submenus(self, menu_id: UUID) -> list[SubMenu]: @@ -52,8 +52,6 @@ class SubMenuRepository: ) submenu = await self.db.execute(query) submenu = submenu.scalars().one_or_none() - if submenu is None: - return None return submenu async def update_submenu_item( @@ -73,10 +71,9 @@ class SubMenuRepository: updated_submenu = await self.db.execute(qr) return updated_submenu.scalar_one() - async def delete_submenu_item(self, menu_id: UUID, submenu_id: UUID) -> int: + async def delete_submenu_item(self, menu_id: UUID, submenu_id: UUID) -> None: query = delete(SubMenu).where( SubMenu.id == submenu_id, ) await self.db.execute(query) await self.db.commit() - return 200 diff --git a/fastfood/service/dish.py b/fastfood/service/dish.py index 5b921ed..4ea3fe9 100644 --- a/fastfood/service/dish.py +++ b/fastfood/service/dish.py @@ -125,13 +125,11 @@ class DishService: return dish - async def del_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID) -> int: - response = await self.dish_repo.delete_dish_item( + async def del_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID) -> None: + await self.dish_repo.delete_dish_item( menu_id, submenu_id, dish_id, ) await self.cache.delete(key=str(menu_id), bg_task=self.bg_tasks) await self.cache.invalidate(key=str(menu_id), bg_task=self.bg_tasks) - - return response diff --git a/fastfood/service/menu.py b/fastfood/service/menu.py index 48147e6..d9c26e9 100644 --- a/fastfood/service/menu.py +++ b/fastfood/service/menu.py @@ -104,8 +104,7 @@ class MenuService: await self.cache.invalidate(key=str(menu_id), bg_task=self.bg_tasks) return menu - async def del_menu(self, menu_id: UUID): - data = await self.menu_repo.delete_menu_item(menu_id) + async def del_menu(self, menu_id: UUID) -> None: + await self.menu_repo.delete_menu_item(menu_id) await self.cache.delete(key=str(menu_id), bg_task=self.bg_tasks) await self.cache.invalidate(key=str(menu_id), bg_task=self.bg_tasks) - return data diff --git a/fastfood/service/submenu.py b/fastfood/service/submenu.py index db23343..68aefc1 100644 --- a/fastfood/service/submenu.py +++ b/fastfood/service/submenu.py @@ -106,8 +106,8 @@ class SubmenuService: return submenu - async def del_menu(self, menu_id: UUID, submenu_id: UUID) -> int: - code = await self.submenu_repo.delete_submenu_item(menu_id, submenu_id) + async def del_menu(self, menu_id: UUID, submenu_id: UUID) -> None: + await self.submenu_repo.delete_submenu_item(menu_id, submenu_id) await self.cache.delete( key=self.key( 'submenu', @@ -117,4 +117,3 @@ class SubmenuService: bg_task=self.bg_tasks, ) await self.cache.invalidate(key=str(menu_id), bg_task=self.bg_tasks) - return code