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"],