From 24c3a91f99a9357452100f5a5950cdc6a3515477 Mon Sep 17 00:00:00 2001 From: Zoom-Developer Date: Mon, 4 Nov 2024 17:35:45 +0300 Subject: [PATCH] final fix of get user --- backend/src/domain/likes/repository.py | 4 ++-- backend/src/interface/rabbit/admin.py | 4 ++-- bot/src/models/admin.py | 2 +- bot/src/rabbit/routers/admin.py | 9 ++++----- bot/src/rabbit/routers/telegram.py | 16 +++++++++------- bot/src/telegram/utlls.py | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/backend/src/domain/likes/repository.py b/backend/src/domain/likes/repository.py index 3849aa9..7a70c31 100644 --- a/backend/src/domain/likes/repository.py +++ b/backend/src/domain/likes/repository.py @@ -1,4 +1,4 @@ -from sqlmodel import select, delete, insert +from sqlmodel import desc, select, delete, insert from infrastructure.db import BaseRepository, Like, User @@ -19,7 +19,7 @@ async def get_byuser(self, user: User, second_user: User) -> Like | None: return res.first() async def get_mutually(self, user: User) -> list[User]: - query = select(User).join_from(Like, Like.target_user).filter((Like.user_id == user.id) & (Like.is_mutually == True)) + query = select(User).join_from(Like, Like.target_user).filter((Like.user_id == user.id) & (Like.is_mutually == True)).order_by(desc(Like.created_at)) res = await self.session.exec(query) return res.all() diff --git a/backend/src/interface/rabbit/admin.py b/backend/src/interface/rabbit/admin.py index aafd81d..0cd627f 100644 --- a/backend/src/interface/rabbit/admin.py +++ b/backend/src/interface/rabbit/admin.py @@ -39,10 +39,10 @@ async def ban_user(data: VerifyUser) -> TelegramRequestResponse: @router.subscriber("user") @router.publisher("user-res") -async def ban_user(data: GetUser) -> TelegramRequestResponse: +async def ban_user(data: GetUser) -> GetUserResponse: user = await UserRepository().get(data.user_id) if not user: - return TelegramRequestResponse(msg_id = data.msg_id, success = False) + return GetUserResponse(msg_id = data.msg_id, success = False, text = "", attachments = []) return GetUserResponse( text = f"\nИмя: {user.mention} ({user.id})" diff --git a/bot/src/models/admin.py b/bot/src/models/admin.py index 0ea0043..05e82dc 100644 --- a/bot/src/models/admin.py +++ b/bot/src/models/admin.py @@ -22,4 +22,4 @@ class TelegramRequestResponse(TelegramRequest): class GetUserResponse(TelegramRequestResponse): text: str - attachments: str \ No newline at end of file + attachments: list[str] \ No newline at end of file diff --git a/bot/src/rabbit/routers/admin.py b/bot/src/rabbit/routers/admin.py index dacdc35..ef92e29 100644 --- a/bot/src/rabbit/routers/admin.py +++ b/bot/src/rabbit/routers/admin.py @@ -10,7 +10,7 @@ router = RabbitRouter("adm_") @router.subscriber("banned") -async def msg(res: TelegramRequestResponse) -> None: +async def banned(res: TelegramRequestResponse) -> None: await bot.send_message( chat_id = TG_ADMIN_CHAT, reply_to_message_id = res.msg_id, @@ -18,7 +18,7 @@ async def msg(res: TelegramRequestResponse) -> None: ) @router.subscriber("unbanned") -async def msg(res: TelegramRequestResponse) -> None: +async def unbanned(res: TelegramRequestResponse) -> None: await bot.send_message( chat_id = TG_ADMIN_CHAT, reply_to_message_id = res.msg_id, @@ -26,7 +26,7 @@ async def msg(res: TelegramRequestResponse) -> None: ) @router.subscriber("verified") -async def msg(res: TelegramRequestResponse) -> None: +async def verified(res: TelegramRequestResponse) -> None: await bot.send_message( chat_id = TG_ADMIN_CHAT, reply_to_message_id = res.msg_id, @@ -34,7 +34,7 @@ async def msg(res: TelegramRequestResponse) -> None: ) @router.subscriber("user-res") -async def msg(res: TelegramRequestResponse | GetUserResponse) -> None: +async def get_user(res: GetUserResponse) -> None: if not res.success: return await bot.send_message( chat_id = TG_ADMIN_CHAT, @@ -44,6 +44,5 @@ async def msg(res: TelegramRequestResponse | GetUserResponse) -> None: await send_media( chat_id = TG_ADMIN_CHAT, text = res.text, - parse_mode = "markdown", files = res.attachments ) \ No newline at end of file diff --git a/bot/src/rabbit/routers/telegram.py b/bot/src/rabbit/routers/telegram.py index 090ae7e..d4f5f63 100644 --- a/bot/src/rabbit/routers/telegram.py +++ b/bot/src/rabbit/routers/telegram.py @@ -10,15 +10,17 @@ router = RabbitRouter("tg_") @router.subscriber("msg") -async def msg(msg: SendMessage | SendAdminMessage) -> None: - await bot.send_message( - chat_id = msg.chat_id if msg.chat_id != -1 else TG_ADMIN_CHAT, - text = msg.text, - parse_mode = msg.parse_mode - ) +async def sendmsg(msg: SendMessage | SendAdminMessage) -> None: + try: + await bot.send_message( + chat_id = msg.chat_id if msg.chat_id != -1 else TG_ADMIN_CHAT, + text = msg.text, + parse_mode = msg.parse_mode + ) + except: pass @router.subscriber("media") -async def msg(msg: SendMediaMessage | SendAdminMediaMessage) -> None: +async def sendmedia(msg: SendMediaMessage | SendAdminMediaMessage) -> None: await send_media( chat_id = msg.chat_id if msg.chat_id != -1 else TG_ADMIN_CHAT, text = msg.text, diff --git a/bot/src/telegram/utlls.py b/bot/src/telegram/utlls.py index 34e166a..ef9ad27 100644 --- a/bot/src/telegram/utlls.py +++ b/bot/src/telegram/utlls.py @@ -3,7 +3,7 @@ from .bot import bot -async def send_media(chat_id: int, text: str, files: list[str], parse_mode: str = "markdown") -> None: +async def send_media(chat_id: int, text: str, files: list[str], parse_mode: str = "html") -> None: await bot.send_media_group( chat_id = chat_id, media = [