2024-02-02 23:38:12 +03:00
|
|
|
from httpx import AsyncClient, Response
|
|
|
|
|
2024-02-04 21:40:58 +03:00
|
|
|
from .urls import reverse_url
|
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
response: Response = await ac.get(reverse_url('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(
|
|
|
|
reverse_url('menu', menu_id=data.get('id'))
|
|
|
|
)
|
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-04 21:40:58 +03:00
|
|
|
response: Response = await ac.post(reverse_url('menus'), 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-04 21:40:58 +03:00
|
|
|
reverse_url('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(
|
|
|
|
reverse_url('menu', menu_id=data.get('id')),
|
|
|
|
)
|
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(
|
|
|
|
reverse_url('submenus', menu_id=menu.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,
|
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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'submenu',
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
reverse_url('submenu', 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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'submenu',
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'submenu',
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'dishes',
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'dish',
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'dishes',
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'dish',
|
|
|
|
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-04 21:40:58 +03:00
|
|
|
reverse_url(
|
|
|
|
'dish',
|
|
|
|
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
|