Skip to content

Commit

Permalink
users page count
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoom-Developer committed Nov 7, 2024
1 parent 32ae6fa commit a69ff76
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions backend/src/infrastructure/rabbit/middlewares.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import traceback
from typing import Any
from faststream import BaseMiddleware, ExceptionMiddleware

Expand Down Expand Up @@ -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")
13 changes: 9 additions & 4 deletions backend/src/interface/rabbit/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from faststream.rabbit import RabbitRouter
import math

from application.tg.service import TelegramService
from application.user.rabbit import get_user
Expand Down Expand Up @@ -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"<b>Всего:</b> {len(users)}\n\n" + '\n'.join([
f"{i}. {user.mention} (<code>{user.id}</code>){' 🚫' if user.is_banned else ''}{' ✅' if user.verify else ''}"
for i, user in enumerate(users, data.offset + 1)
]),
text =
f"<b>Страница:</b> {math.ceil(data.offset / data.limit) + 1} / {math.ceil(total / data.limit)}"
f"\n<b>Всего:</b> {len(users)}\n\n"
+ '\n'.join([
f"{i}. {user.mention} (<code>{user.id}</code>){' 🚫' if user.is_banned else ''}{' ✅' if user.verify else ''}"
for i, user in enumerate(users, data.offset + 1)
]),
count = len(users)
)
)
1 change: 1 addition & 0 deletions bot/src/interface/telegram/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ async def help(msg: Message):
"\n<b>/unverify</b> - Отзыв верификации пользователя"
"\n<b>/denyverify</b> - Отказ в верификации пользователю"
"\n<b>/get</b> - Получение информации о пользователе"
"\n<b>/users</b> - Список пользователей"
)

0 comments on commit a69ff76

Please sign in to comment.