|
1 | | -from typing import Any |
| 1 | +from typing import Any, List |
2 | 2 | from aiogram import types |
3 | 3 | from aiogram.fsm.context import FSMContext |
4 | 4 |
|
| 5 | +from bot.utills import format_date |
5 | 6 | from messages import MESSAGES |
| 7 | +from service.idea import IdeaService |
6 | 8 | from service.user import UserService |
7 | 9 | from bot.buttons import get_language_keyboard, menu_reply_keyboard |
8 | 10 | from states import DialogStates |
9 | 11 |
|
10 | | - |
11 | 12 | # Start Command Handler |
12 | 13 | async def start_command(message: types.Message): |
13 | 14 | user_id: int = message.from_user.id |
@@ -68,3 +69,27 @@ async def idea_command(message: types.Message, state: FSMContext): |
68 | 69 | await message.answer(MESSAGES[language]['IDEA_RESPONSE']) |
69 | 70 | await state.set_state(DialogStates.waiting_for_idea) |
70 | 71 |
|
| 72 | +# Show Ideas Handler |
| 73 | +async def ideas_command(message: types.Message): |
| 74 | + user_id: int = message.from_user.id |
| 75 | + user_find: Any = await UserService.get_user_by_id(user_id) |
| 76 | + language: str = await UserService.get_user_language(user_id) |
| 77 | + |
| 78 | + if not user_find: |
| 79 | + await message.answer(MESSAGES['ENGLISH']['AUTHORIZATION_PROBLEM']) |
| 80 | + else: |
| 81 | + ideas: List[str] = await IdeaService.get_all_ideas_by_user_id(user_id) |
| 82 | + if not ideas: |
| 83 | + print(f"--[INFO] - User with id: {user_id} - has no ideas.") |
| 84 | + await message.answer(MESSAGES[language]['NO_IDEAS']) |
| 85 | + else: |
| 86 | + print(f"--[INFO] - User with id: {user_id} - has ideas: {ideas}") |
| 87 | + |
| 88 | + dividers: str = "\n" + ("-" * int(len(MESSAGES[language]['IDEAS_SHOW']) * 1.65)) |
| 89 | + |
| 90 | + formatted_ideas = MESSAGES[language]['IDEAS_SHOW'] + dividers + "\n" + "\n".join( |
| 91 | + f"# {num}. {idea['idea_name']}\n[{format_date(idea['creation_date'])}]" |
| 92 | + for num, idea in enumerate(ideas, start=1) |
| 93 | + ) |
| 94 | + |
| 95 | + await message.answer(formatted_ideas, reply_markup=menu_reply_keyboard()) |
0 commit comments