from fastapi import APIRouter, Depends from ..utils.dependencies import right_checkers from ..server_data import ServerData data = ServerData() router = APIRouter() @router.get("/commands", tags=["Commands management"], dependencies=[Depends(right_checkers["read"])]) async def get_commands() -> dict: '''Обработчик, отвечающий на запросы списка команд.''' response = {} for command_id, command_object in data.commands.items(): response.update({command_id: {"title": command_object.title, "category": command_object.category, "icon": command_object.icon, "command": command_object.command}}) return response @router.get("/commands/{cid}", tags=["Commands management"], dependencies=[Depends(right_checkers["read"])]) async def get_command(cid: int) -> dict: '''Обработчик запросов списка команд.''' if cid not in data.commands_instances: # TODO добавить какую-то обработку ошибки. pass return {'id': cid, 'name': f'command_{cid}'} @router.get("/commands/{cid}/groups", tags=["Commands management"], dependencies=[Depends(right_checkers["read"])]) async def get_command_parameters_groups(cid: int) -> dict: '''Обработчик запросов на получение групп параметров указанной команды.''' pass @router.get("/commands/{cid}/parameters", tags=["Commands management"], dependencies=[Depends(right_checkers["read"])]) async def get_command_parameters(cid: int) -> dict: '''Обработчик запросов на получение параметров указанной команды.''' pass @router.post("/commands/{command_id}", tags=["Commands management"], dependencies=[Depends(right_checkers["write"])]) async def post_command(command_id: str) -> int: if command_id not in data.commands: # TODO добавить какую-то обработку ошибки. pass return