From aebeaa833fd3758ca014a0c4b2202c0ce630923b Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 30 Sep 2026 16:57:54 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BF=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20/words/all=20+=20/texts/all=20+=20CRUD=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=BE=D0=B2=20+=20=D0=B3=D0=BB?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=B4=D1=83?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/admin_content.py | 45 +++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/routers/admin_content.py b/routers/admin_content.py index 7718e71..3b015f1 100644 --- a/routers/admin_content.py +++ b/routers/admin_content.py @@ -48,6 +48,8 @@ Admin Content Router — контент-менеджер для редактир 🔧 НОВОЕ (30.09.2026): DELETE /admin/content/texts/text/{text_id} — удаление текста из редактора. + +🔧 ОБНОВЛЕНО (30.09.2026): /texts/all — пагинация + total. """ import logging import re @@ -710,24 +712,37 @@ async def list_all_texts( request: Request, level: Optional[str] = None, q: Optional[str] = None, - limit: int = 500, + page: int = 1, + limit: int = 50, ): """ - Полный список текстов (с id) для редактора. - Поиск по PL/RU/UK/EN. + 🔧 ОБНОВЛЕНО (30.09.2026): пагинация + total. + + Возвращает: + { + "total": 400, # всего под фильтром + "page": 1, # текущая страница + "limit": 50, # размер страницы + "pages": 8, # всего страниц + "texts": [...], # тексты текущей страницы + } """ telegram_id, _ = await require_auth(request) _require_admin(telegram_id) + if page < 1: + page = 1 if limit < 1: limit = 1 - elif limit > 2000: - limit = 2000 + elif limit > 500: + limit = 500 + + offset = (page - 1) * limit pool = await get_pool() async with pool.acquire() as conn: conditions = [] - params = [] + params: list = [] idx = 1 if level and level in LEVELS: @@ -746,19 +761,29 @@ async def list_all_texts( idx += 1 where = ("WHERE " + " AND ".join(conditions)) if conditions else "" - params.append(limit) + # Total + total = await conn.fetchval(f""" + SELECT COUNT(*) FROM sentences {where} + """, *params) or 0 + + # Page rows = await conn.fetch(f""" SELECT id, level, sentence_number, sentence_pl, translation_ru, translation_uk, translation_en, difficulty FROM sentences {where} ORDER BY level, sentence_number - LIMIT ${idx} - """, *params) + LIMIT ${idx} OFFSET ${idx + 1} + """, *params, limit, offset) + + pages = (total + limit - 1) // limit if limit > 0 else 1 return { - "total": len(rows), + "total": total, + "page": page, + "limit": limit, + "pages": pages, "texts": [ { "id": r["id"],