From 63c1b58fc9f9c1eb44f3aa91fd61dd9b4233052b Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Thu, 15 Feb 2024 12:17:19 +0300 Subject: [PATCH] Restore post command --- handlers/admin_commands.py | 2 ++ handlers/message_handlers/restore_command.py | 20 ++++++++++++++++++++ neuroapi/_methods/post.py | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 handlers/message_handlers/restore_command.py diff --git a/handlers/admin_commands.py b/handlers/admin_commands.py index edb5d92..ffc36ad 100644 --- a/handlers/admin_commands.py +++ b/handlers/admin_commands.py @@ -10,6 +10,7 @@ from handlers.message_handlers.newpost_command import (NewPostCommand, from handlers.message_handlers.post_command import PostCommand from handlers.message_handlers.preview_command import PreviewCommand from handlers.message_handlers.reply_to_user import ReplyToUserCommand +from handlers.message_handlers.restore_command import RestoreCommand from handlers.message_handlers.settings_command import SettingsCommand from handlers.message_handlers.update_settings import UpdateSettingsCommand from handlers.middlewares.media_group import MediaGroupMiddleware @@ -29,6 +30,7 @@ class AdminCommands(Handler): (UpdateSettingsCommand, PostCommand(self.bot).handler), EditCommand, PostCommand, + RestoreCommand, SettingsCommand, ]) self.router.message.middleware(MediaGroupMiddleware()) diff --git a/handlers/message_handlers/restore_command.py b/handlers/message_handlers/restore_command.py new file mode 100644 index 0000000..77a33b3 --- /dev/null +++ b/handlers/message_handlers/restore_command.py @@ -0,0 +1,20 @@ +from aiogram.filters import Command +from aiogram.types import Message + +from neuroapi import neuroapi + +from .handler import MessageHandlerABC + + +class RestoreCommand(MessageHandlerABC): + filter = Command('restore') + async def _command(self, message: Message): + try: + command = message.text.split() + if len(command) != 2: + raise Exception('Неверное количество аргументов') + order = command[1] + await neuroapi.post.restore_post(order) + await message.answer('Пост восстановлен') + except Exception as e: + await message.answer(f'Ошибка: {e}') \ No newline at end of file diff --git a/neuroapi/_methods/post.py b/neuroapi/_methods/post.py index 99b1189..f69621c 100644 --- a/neuroapi/_methods/post.py +++ b/neuroapi/_methods/post.py @@ -119,3 +119,11 @@ class Post(ApiMethod): if 'statusCode' in data: raise Exception(data['message']) return [neuroTypes.Post.from_dict(post) for post in data] + + async def restore_post(self, order: str): + async with ClientSession() as session: + response = await session.put(self.api_url+f'/post/restore-post-by-order/{order}') + data = await response.json() + if 'statusCode' in data: + raise Exception(data['message']) + return neuroTypes.Post.from_dict(data)