aboutsummaryrefslogtreecommitdiff
path: root/handlers/user/announcements.py
diff options
context:
space:
mode:
Diffstat (limited to 'handlers/user/announcements.py')
-rw-r--r--handlers/user/announcements.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/handlers/user/announcements.py b/handlers/user/announcements.py
index 8f4aa43..dc85b54 100644
--- a/handlers/user/announcements.py
+++ b/handlers/user/announcements.py
@@ -16,11 +16,17 @@ router = Router(name="announcements")
16PAGE_SIZE = 5 16PAGE_SIZE = 5
17 17
18 18
19async def get_reply_markup(page: int, session: AsyncSession) -> InlineKeyboardMarkup: 19async def get_reply_markup(
20 page: int,
21 session: AsyncSession,
22) -> InlineKeyboardMarkup | None:
20 total = await session.scalar(select(count()).select_from(Announcement)) 23 total = await session.scalar(select(count()).select_from(Announcement))
21 assert total is not None 24 assert total is not None
22 total_pages = ceil(total / PAGE_SIZE) 25 total_pages = ceil(total / PAGE_SIZE)
23 26
27 if total == 0:
28 return None
29
24 page = max(0, min(page, total_pages - 1)) 30 page = max(0, min(page, total_pages - 1))
25 query = ( 31 query = (
26 select(Announcement) 32 select(Announcement)
@@ -64,10 +70,13 @@ async def get_reply_markup(page: int, session: AsyncSession) -> InlineKeyboardMa
64 70
65@router.message(Command("announcements")) 71@router.message(Command("announcements"))
66async def command(msg: Message, bot: Bot, session: AsyncSession) -> None: 72async def command(msg: Message, bot: Bot, session: AsyncSession) -> None:
67 await msg.answer( 73 reply_markup = await get_reply_markup(0, session)
68 "Выберете анонс для просмотра.", 74
69 reply_markup=await get_reply_markup(0, session), 75 if reply_markup is None:
70 ) 76 await msg.answer("Нету анонсов для просмотра.")
77 return
78
79 await msg.answer("Выберете анонс для просмотра.", reply_markup=reply_markup)
71 80
72 81
73@router.callback_query(AnnouncePageClb.filter()) 82@router.callback_query(AnnouncePageClb.filter())
@@ -80,7 +89,7 @@ async def page(
80 89
81 reply_markup = await get_reply_markup(callback_data.page, session) 90 reply_markup = await get_reply_markup(callback_data.page, session)
82 await clb.message.edit_text( 91 await clb.message.edit_text(
83 "Выберете анонс для просмотра.", 92 "Выберете анонс для просмотра:",
84 reply_markup=reply_markup, 93 reply_markup=reply_markup,
85 ) 94 )
86 95