fix: typehint в serv/repos

develop
Сергей Ванюшкин 2024-02-06 15:50:02 +03:00
parent 095ab07ebb
commit 7d4c4d9be3
6 changed files with 12 additions and 22 deletions

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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