Restore post command

This commit is contained in:
2024-02-15 12:17:19 +03:00
parent 77a916dc0b
commit 63c1b58fc9
3 changed files with 30 additions and 0 deletions

View File

@@ -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())

View File

@@ -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}')

View File

@@ -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)