service.dish typehint
parent
628babc295
commit
015a0bcc87
|
@ -15,15 +15,13 @@ class DishService:
|
||||||
dish_repo: DishRepository = Depends(),
|
dish_repo: DishRepository = Depends(),
|
||||||
redis_client: redis.Redis = Depends(get_async_redis_client),
|
redis_client: redis.Redis = Depends(get_async_redis_client),
|
||||||
background_tasks: BackgroundTasks = None,
|
background_tasks: BackgroundTasks = None,
|
||||||
):
|
) -> None:
|
||||||
self.dish_repo = dish_repo
|
self.dish_repo = dish_repo
|
||||||
self.cache_client = RedisRepository(redis_client)
|
self.cache_client = RedisRepository(redis_client)
|
||||||
self.background_tasks = background_tasks
|
self.background_tasks = background_tasks
|
||||||
|
|
||||||
async def read_dishes(self, menu_id: UUID, submenu_id: UUID):
|
async def read_dishes(self, menu_id: UUID, submenu_id: UUID) -> list[dict]:
|
||||||
data = await self.dish_repo.get_dishes(menu_id, submenu_id)
|
data = await self.dish_repo.get_dishes(menu_id, submenu_id)
|
||||||
if data:
|
|
||||||
print(type(data[0]))
|
|
||||||
response = []
|
response = []
|
||||||
for row in data:
|
for row in data:
|
||||||
dish = row.__dict__
|
dish = row.__dict__
|
||||||
|
@ -36,7 +34,7 @@ class DishService:
|
||||||
menu_id: UUID,
|
menu_id: UUID,
|
||||||
submenu_id: UUID,
|
submenu_id: UUID,
|
||||||
dish_data: DishBase,
|
dish_data: DishBase,
|
||||||
):
|
) -> dict:
|
||||||
dish = Dish_db(**dish_data.model_dump())
|
dish = Dish_db(**dish_data.model_dump())
|
||||||
data = await self.dish_repo.create_dish_item(
|
data = await self.dish_repo.create_dish_item(
|
||||||
menu_id,
|
menu_id,
|
||||||
|
@ -47,28 +45,27 @@ class DishService:
|
||||||
response['price'] = str(response['price'])
|
response['price'] = str(response['price'])
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def read_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID):
|
async def read_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID) -> dict:
|
||||||
data = await self.dish_repo.get_dish_item(menu_id, submenu_id, dish_id)
|
data = await self.dish_repo.get_dish_item(menu_id, submenu_id, dish_id)
|
||||||
if data is None:
|
if data is None:
|
||||||
return
|
return {}
|
||||||
response = data.__dict__
|
response = data.__dict__
|
||||||
response['price'] = str(response['price'])
|
response['price'] = str(response['price'])
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def update_dish(
|
async def update_dish(
|
||||||
self, menu_id: UUID, submenu_id: UUID, dish_id, dish_data: DishBase
|
self, menu_id: UUID, submenu_id: UUID, dish_id, dish_data: DishBase
|
||||||
):
|
) -> dict:
|
||||||
dish = Dish_db(**dish_data.model_dump())
|
dish = Dish_db(**dish_data.model_dump())
|
||||||
data = await self.dish_repo.update_dish_item(menu_id, submenu_id, dish_id, dish)
|
data = await self.dish_repo.update_dish_item(menu_id, submenu_id, dish_id, dish)
|
||||||
response = data.__dict__
|
response = data.__dict__
|
||||||
response['price'] = str(response['price'])
|
response['price'] = str(response['price'])
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def del_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID):
|
async def del_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID) -> int:
|
||||||
data = await self.dish_repo.delete_dish_item(
|
response = await self.dish_repo.delete_dish_item(
|
||||||
menu_id,
|
menu_id,
|
||||||
submenu_id,
|
submenu_id,
|
||||||
dish_id,
|
dish_id,
|
||||||
)
|
)
|
||||||
return data
|
return response
|
||||||
|
|
Loading…
Reference in New Issue