This commit is contained in:
2026-02-27 22:44:02 +03:00
parent 55c3629868
commit c57a40b09a
14 changed files with 331 additions and 69 deletions
@@ -7,15 +7,16 @@ from dishka.integrations.aiogram_dialog import inject
from dutylog.application.bot.user_dialogs.states import MainMenuSG
from dutylog.infrastructure.database.repositories.users_repository import UsersRepository
from dutylog.infrastructure.database.repositories.residents_repository import ResidentsRepository
from dutylog.infrastructure.database.repositories.hours_transactions_repository import HoursTransactionsRepository
from dutylog.infrastructure.utils.config import Config
@inject
async def get_main_menu_data(
dialog_manager: DialogManager,
event_from_user: User,
users_repository: FromDishka[UsersRepository],
residents_repository: FromDishka[ResidentsRepository],
config: FromDishka[Config],
**kwargs,
):
@@ -37,14 +38,26 @@ async def get_main_menu_data(
greeting = f"👋 <b>Привет, {event_from_user.first_name}!</b>"
if not is_admin and not is_creator:
content = f"""
resident = await residents_repository.get_resident_by_user_id(event_from_user.id)
if not resident:
content = f"""
{greeting}
<blockquote>⚠️ <b>Профиль не найден</b></blockquote>
Вы еще не привязаны к резиденту.
Обратитесь к администратору для регистрации.
"""
else:
content = f"""
{greeting}
⏰ <b>Ваши часы дежурств</b>
<blockquote>🟢 <b>Отработанные часы:</b> <code>{user.active_hours}</code> ч
<blockquote>🟢 <b>Отработанные часы:</b> <code>{resident.active_hours}</code> ч
━━━━━━━━━━━━━━━━
🔴 Неотработанные часы: <code>{user.inactive_hours}</code> ч</blockquote>
🔴 Неотработанные часы: <code>{resident.inactive_hours}</code> ч</blockquote>
"""
else:
content = f"""
@@ -58,35 +71,45 @@ async def get_main_menu_data(
return {
"content": content,
"is_regular_user": not is_admin and not is_creator,
"has_resident": resident is not None if not is_admin and not is_creator else False,
}
@inject
async def get_history_data(
dialog_manager: DialogManager,
event_from_user: User,
residents_repository: FromDishka[ResidentsRepository],
transactions_repository: FromDishka[HoursTransactionsRepository],
**kwargs,
):
transactions = await transactions_repository.get_user_history(event_from_user.id)
last_10 = transactions[:10]
resident = await residents_repository.get_resident_by_user_id(event_from_user.id)
if not last_10:
if not resident:
history_text = """
<blockquote>📜 <b>История операций</b></blockquote>
<i>Профиль не найден</i>
"""
else:
transactions = await transactions_repository.get_resident_history(resident.id)
last_10 = transactions[:10]
if not last_10:
history_text = """
<blockquote>📜 <b>История операций</b></blockquote>
<i>История операций пуста</i>
"""
else:
history_lines = []
for tx in last_10:
emoji = "" if tx.transaction_type == "increase" else ""
date_str = tx.created_at.strftime("%d.%m.%Y %H:%M")
history_lines.append(
f"{emoji} <code>{tx.amount}</code> ч • <i>{date_str}</i>"
)
history_text = f"""
else:
history_lines = []
for tx in last_10:
emoji = "" if tx.transaction_type == "increase" else ""
date_str = tx.created_at.strftime("%d.%m.%Y %H:%M")
history_lines.append(
f"{emoji} <code>{tx.amount}</code> ч • <i>{date_str}</i>"
)
history_text = f"""
<blockquote>📜 <b>История операций</b></blockquote>
{"".join(f"{line}\n" for line in history_lines)}
@@ -103,7 +126,7 @@ main_menu_dialog = Dialog(
Const("📜 История"),
id="history_btn",
state=MainMenuSG.history,
when="is_regular_user",
when="has_resident",
),
state=MainMenuSG.main,
getter=get_main_menu_data,