From a69ff767164a553ceebcde5c0c5c08a706e403fa Mon Sep 17 00:00:00 2001 From: Zoom-Developer Date: Thu, 7 Nov 2024 19:04:36 +0300 Subject: [PATCH] users page count --- backend/src/infrastructure/rabbit/middlewares.py | 2 ++ backend/src/interface/rabbit/admin.py | 13 +++++++++---- bot/src/interface/telegram/help.py | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/infrastructure/rabbit/middlewares.py b/backend/src/infrastructure/rabbit/middlewares.py index 9e00e52..a577cdb 100644 --- a/backend/src/infrastructure/rabbit/middlewares.py +++ b/backend/src/infrastructure/rabbit/middlewares.py @@ -1,3 +1,4 @@ +import traceback from typing import Any from faststream import BaseMiddleware, ExceptionMiddleware @@ -25,4 +26,5 @@ def rabbit_error(exc: RabbitError): @exc_middlware.add_handler(Exception, publish=True) def rabbit_error(exc: Exception): + traceback.print_exception(exc) return RabbitRequestResponse(success = False, error = "Internal error") diff --git a/backend/src/interface/rabbit/admin.py b/backend/src/interface/rabbit/admin.py index e96e7fa..e8987db 100644 --- a/backend/src/interface/rabbit/admin.py +++ b/backend/src/interface/rabbit/admin.py @@ -1,4 +1,5 @@ from faststream.rabbit import RabbitRouter +import math from application.tg.service import TelegramService from application.user.rabbit import get_user @@ -59,12 +60,16 @@ async def user(data: UserRequest) -> RabbitRequestResponse[GetUserResponse]: @router.subscriber("users") async def users(data: GetUsers) -> RabbitRequestResponse[GetUserResponse]: users = await UserRepository().get_all(data.offset, data.limit) + total = await UserRepository().count() return RabbitRequestResponse( response = GetUsersResponse( - text = f"Всего: {len(users)}\n\n" + '\n'.join([ - f"{i}. {user.mention} ({user.id}){' 🚫' if user.is_banned else ''}{' ✅' if user.verify else ''}" - for i, user in enumerate(users, data.offset + 1) - ]), + text = + f"Страница: {math.ceil(data.offset / data.limit) + 1} / {math.ceil(total / data.limit)}" + f"\nВсего: {len(users)}\n\n" + + '\n'.join([ + f"{i}. {user.mention} ({user.id}){' 🚫' if user.is_banned else ''}{' ✅' if user.verify else ''}" + for i, user in enumerate(users, data.offset + 1) + ]), count = len(users) ) ) \ No newline at end of file diff --git a/bot/src/interface/telegram/help.py b/bot/src/interface/telegram/help.py index e35d09d..4d5f928 100644 --- a/bot/src/interface/telegram/help.py +++ b/bot/src/interface/telegram/help.py @@ -15,4 +15,5 @@ async def help(msg: Message): "\n/unverify - Отзыв верификации пользователя" "\n/denyverify - Отказ в верификации пользователю" "\n/get - Получение информации о пользователе" + "\n/users - Список пользователей" ) \ No newline at end of file