2024-02-02 23:38:12 +03:00
|
|
|
from httpx import AsyncClient, Response
|
|
|
|
|
2024-02-06 15:12:32 +03:00
|
|
|
from .urls import reverse
|
2024-02-04 21:40:58 +03:00
|
|
|
|
2024-02-02 23:38:12 +03:00
|
|
|
|
|
|
|
class Repository:
|
|
|
|
class Menu:
|
|
|
|
@staticmethod
|
2024-02-03 01:08:04 +03:00
|
|
|
async def read_all(ac: AsyncClient) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""чтение всех меню"""
|
|
|
|
|
2024-02-06 15:12:32 +03:00
|
|
|
response: Response = await ac.get(reverse('get_menus'))
|
2024-02-02 23:38:12 +03:00
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
2024-02-03 01:08:04 +03:00
|
|
|
async def get(ac: AsyncClient, data: dict) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""Получение меню по id"""
|
2024-02-04 21:40:58 +03:00
|
|
|
response: Response = await ac.get(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse('get_menu', menu_id=data.get('id'))
|
2024-02-04 21:40:58 +03:00
|
|
|
)
|
2024-02-02 23:38:12 +03:00
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
2024-02-03 01:08:04 +03:00
|
|
|
async def write(ac: AsyncClient, data: dict) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""создания меню"""
|
2024-02-06 15:12:32 +03:00
|
|
|
response: Response = await ac.post(reverse('add_menu'), json=data)
|
2024-02-02 23:38:12 +03:00
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
2024-02-03 01:08:04 +03:00
|
|
|
async def update(ac: AsyncClient, data: dict) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""Обновление меню по id"""
|
|
|
|
response: Response = await ac.patch(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse('update_menu', menu_id=data.get('id')),
|
2024-02-02 23:38:12 +03:00
|
|
|
json=data,
|
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def delete(ac: AsyncClient, data: dict) -> int:
|
|
|
|
"""Удаление меню по id"""
|
2024-02-04 21:40:58 +03:00
|
|
|
response: Response = await ac.delete(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse('delete_menu', menu_id=data.get('id')),
|
2024-02-04 21:40:58 +03:00
|
|
|
)
|
2024-02-02 23:38:12 +03:00
|
|
|
return response.status_code
|
|
|
|
|
|
|
|
class Submenu:
|
|
|
|
@staticmethod
|
2024-02-03 01:08:04 +03:00
|
|
|
async def read_all(ac: AsyncClient, menu: dict) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""чтение всех меню"""
|
2024-02-04 21:40:58 +03:00
|
|
|
response: Response = await ac.get(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse('get_submenus', menu_id=menu.get('id')),
|
2024-02-04 21:40:58 +03:00
|
|
|
)
|
2024-02-02 23:38:12 +03:00
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def get(
|
|
|
|
ac: AsyncClient,
|
|
|
|
menu: dict,
|
|
|
|
submenu: dict,
|
2024-02-03 01:08:04 +03:00
|
|
|
) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""Получение меню по id"""
|
|
|
|
response: Response = await ac.get(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'get_submenu',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def write(
|
|
|
|
ac: AsyncClient,
|
|
|
|
menu: dict,
|
|
|
|
submenu: dict,
|
2024-02-03 01:08:04 +03:00
|
|
|
) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""создания меню"""
|
|
|
|
response: Response = await ac.post(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse('create_submenu_item', menu_id=menu.get('id')),
|
2024-02-02 23:38:12 +03:00
|
|
|
json=submenu,
|
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def update(
|
|
|
|
ac: AsyncClient, menu: dict, submenu: dict
|
2024-02-03 01:08:04 +03:00
|
|
|
) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""Обновление меню по id"""
|
|
|
|
response: Response = await ac.patch(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'update_submenu',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
json=submenu,
|
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def delete(ac: AsyncClient, menu: dict, submenu: dict) -> int:
|
|
|
|
"""Удаление меню по id"""
|
|
|
|
response: Response = await ac.delete(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'delete_submenu',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
)
|
|
|
|
return response.status_code
|
|
|
|
|
|
|
|
class Dish:
|
|
|
|
@staticmethod
|
|
|
|
async def read_all(
|
|
|
|
ac: AsyncClient, menu: dict, submenu: dict
|
2024-02-03 01:08:04 +03:00
|
|
|
) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""чтение всех блюд"""
|
|
|
|
response: Response = await ac.get(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'get_dishes',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def get(
|
|
|
|
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
|
2024-02-03 01:08:04 +03:00
|
|
|
) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""Получение блюда по id"""
|
|
|
|
response: Response = await ac.get(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'get_dish',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
dish_id=dish.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def write(
|
|
|
|
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
|
2024-02-03 01:08:04 +03:00
|
|
|
) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""создания блюда"""
|
|
|
|
response: Response = await ac.post(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'create_dish',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
json=dish,
|
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def update(
|
|
|
|
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
|
2024-02-03 01:08:04 +03:00
|
|
|
) -> tuple[int, dict]:
|
2024-02-02 23:38:12 +03:00
|
|
|
"""Обновление блюда по id"""
|
|
|
|
response: Response = await ac.patch(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'update_dish',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
dish_id=dish.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
json=dish,
|
|
|
|
)
|
|
|
|
return response.status_code, response.json()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
async def delete(
|
|
|
|
ac: AsyncClient,
|
|
|
|
menu: dict,
|
|
|
|
submenu: dict,
|
|
|
|
dish: dict,
|
|
|
|
) -> int:
|
|
|
|
"""Удаление блюда по id"""
|
|
|
|
response: Response = await ac.delete(
|
2024-02-06 15:12:32 +03:00
|
|
|
reverse(
|
|
|
|
'delete_dish',
|
2024-02-04 21:40:58 +03:00
|
|
|
menu_id=menu.get('id'),
|
|
|
|
submenu_id=submenu.get('id'),
|
|
|
|
dish_id=dish.get('id'),
|
|
|
|
),
|
2024-02-02 23:38:12 +03:00
|
|
|
)
|
|
|
|
return response.status_code
|
2024-02-11 23:17:57 +03:00
|
|
|
|
|
|
|
class Summary:
|
|
|
|
@staticmethod
|
|
|
|
async def read_summary(ac: AsyncClient) -> tuple[int, dict]:
|
|
|
|
"""чтение summary"""
|
|
|
|
|
|
|
|
response: Response = await ac.get(reverse('get_summary'))
|
|
|
|
return response.status_code, response.json()
|