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: class DishRepository:
def __init__(self, session: AsyncSession = Depends(get_async_session)): def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None:
self.db = session self.db = session
async def get_dishes(self, menu_id: UUID, submenu_id: UUID) -> list[Dish]: async def get_dishes(self, menu_id: UUID, submenu_id: UUID) -> list[Dish]:
@ -62,8 +62,7 @@ class DishRepository:
menu_id: UUID, menu_id: UUID,
submenu_id: UUID, submenu_id: UUID,
dish_id: UUID, dish_id: UUID,
) -> int: ) -> None:
query = delete(Dish).where(Dish.id == dish_id) query = delete(Dish).where(Dish.id == dish_id)
await self.db.execute(query) await self.db.execute(query)
await self.db.commit() await self.db.commit()
return 200

View File

@ -11,7 +11,7 @@ from fastfood.models import Dish, Menu, SubMenu
class MenuRepository: class MenuRepository:
def __init__(self, session: AsyncSession = Depends(get_async_session)): def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None:
self.db = session self.db = session
async def get_menus(self) -> list[Menu]: async def get_menus(self) -> list[Menu]:
@ -44,8 +44,6 @@ class MenuRepository:
) )
menu = await self.db.execute(query) menu = await self.db.execute(query)
menu = menu.scalars().one_or_none() menu = menu.scalars().one_or_none()
if menu is None:
return None
return menu return menu
async def update_menu_item( async def update_menu_item(
@ -60,7 +58,7 @@ class MenuRepository:
updated_menu = await self.db.execute(qr) updated_menu = await self.db.execute(qr)
return updated_menu.scalar_one() 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) query = delete(Menu).where(Menu.id == menu_id)
await self.db.execute(query) await self.db.execute(query)
await self.db.commit() await self.db.commit()

View File

@ -11,7 +11,7 @@ from fastfood.schemas import MenuBase
class SubMenuRepository: class SubMenuRepository:
def __init__(self, session: AsyncSession = Depends(get_async_session)): def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None:
self.db = session self.db = session
async def get_submenus(self, menu_id: UUID) -> list[SubMenu]: async def get_submenus(self, menu_id: UUID) -> list[SubMenu]:
@ -52,8 +52,6 @@ class SubMenuRepository:
) )
submenu = await self.db.execute(query) submenu = await self.db.execute(query)
submenu = submenu.scalars().one_or_none() submenu = submenu.scalars().one_or_none()
if submenu is None:
return None
return submenu return submenu
async def update_submenu_item( async def update_submenu_item(
@ -73,10 +71,9 @@ class SubMenuRepository:
updated_submenu = await self.db.execute(qr) updated_submenu = await self.db.execute(qr)
return updated_submenu.scalar_one() 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( query = delete(SubMenu).where(
SubMenu.id == submenu_id, SubMenu.id == submenu_id,
) )
await self.db.execute(query) await self.db.execute(query)
await self.db.commit() await self.db.commit()
return 200

View File

@ -125,13 +125,11 @@ class DishService:
return dish return dish
async def del_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID) -> int: async def del_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID) -> None:
response = await self.dish_repo.delete_dish_item( await self.dish_repo.delete_dish_item(
menu_id, menu_id,
submenu_id, submenu_id,
dish_id, dish_id,
) )
await self.cache.delete(key=str(menu_id), bg_task=self.bg_tasks) 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) 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) await self.cache.invalidate(key=str(menu_id), bg_task=self.bg_tasks)
return menu return menu
async def del_menu(self, menu_id: UUID): async def del_menu(self, menu_id: UUID) -> None:
data = await self.menu_repo.delete_menu_item(menu_id) 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.delete(key=str(menu_id), bg_task=self.bg_tasks)
await self.cache.invalidate(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 return submenu
async def del_menu(self, menu_id: UUID, submenu_id: UUID) -> int: async def del_menu(self, menu_id: UUID, submenu_id: UUID) -> None:
code = await self.submenu_repo.delete_submenu_item(menu_id, submenu_id) await self.submenu_repo.delete_submenu_item(menu_id, submenu_id)
await self.cache.delete( await self.cache.delete(
key=self.key( key=self.key(
'submenu', 'submenu',
@ -117,4 +117,3 @@ class SubmenuService:
bg_task=self.bg_tasks, bg_task=self.bg_tasks,
) )
await self.cache.invalidate(key=str(menu_id), bg_task=self.bg_tasks) await self.cache.invalidate(key=str(menu_id), bg_task=self.bg_tasks)
return code