feat: пагинация /words/all + /texts/all + CRUD текстов + глобальные дубликаты
This commit is contained in:
+35
-10
@@ -48,6 +48,8 @@ Admin Content Router — контент-менеджер для редактир
|
|||||||
|
|
||||||
🔧 НОВОЕ (30.09.2026): DELETE /admin/content/texts/text/{text_id} —
|
🔧 НОВОЕ (30.09.2026): DELETE /admin/content/texts/text/{text_id} —
|
||||||
удаление текста из редактора.
|
удаление текста из редактора.
|
||||||
|
|
||||||
|
🔧 ОБНОВЛЕНО (30.09.2026): /texts/all — пагинация + total.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
@@ -710,24 +712,37 @@ async def list_all_texts(
|
|||||||
request: Request,
|
request: Request,
|
||||||
level: Optional[str] = None,
|
level: Optional[str] = None,
|
||||||
q: Optional[str] = None,
|
q: Optional[str] = None,
|
||||||
limit: int = 500,
|
page: int = 1,
|
||||||
|
limit: int = 50,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Полный список текстов (с id) для редактора.
|
🔧 ОБНОВЛЕНО (30.09.2026): пагинация + total.
|
||||||
Поиск по PL/RU/UK/EN.
|
|
||||||
|
Возвращает:
|
||||||
|
{
|
||||||
|
"total": 400, # всего под фильтром
|
||||||
|
"page": 1, # текущая страница
|
||||||
|
"limit": 50, # размер страницы
|
||||||
|
"pages": 8, # всего страниц
|
||||||
|
"texts": [...], # тексты текущей страницы
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
telegram_id, _ = await require_auth(request)
|
telegram_id, _ = await require_auth(request)
|
||||||
_require_admin(telegram_id)
|
_require_admin(telegram_id)
|
||||||
|
|
||||||
|
if page < 1:
|
||||||
|
page = 1
|
||||||
if limit < 1:
|
if limit < 1:
|
||||||
limit = 1
|
limit = 1
|
||||||
elif limit > 2000:
|
elif limit > 500:
|
||||||
limit = 2000
|
limit = 500
|
||||||
|
|
||||||
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
pool = await get_pool()
|
pool = await get_pool()
|
||||||
async with pool.acquire() as conn:
|
async with pool.acquire() as conn:
|
||||||
conditions = []
|
conditions = []
|
||||||
params = []
|
params: list = []
|
||||||
idx = 1
|
idx = 1
|
||||||
|
|
||||||
if level and level in LEVELS:
|
if level and level in LEVELS:
|
||||||
@@ -746,19 +761,29 @@ async def list_all_texts(
|
|||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
where = ("WHERE " + " AND ".join(conditions)) if conditions else ""
|
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"""
|
rows = await conn.fetch(f"""
|
||||||
SELECT id, level, sentence_number, sentence_pl,
|
SELECT id, level, sentence_number, sentence_pl,
|
||||||
translation_ru, translation_uk, translation_en, difficulty
|
translation_ru, translation_uk, translation_en, difficulty
|
||||||
FROM sentences
|
FROM sentences
|
||||||
{where}
|
{where}
|
||||||
ORDER BY level, sentence_number
|
ORDER BY level, sentence_number
|
||||||
LIMIT ${idx}
|
LIMIT ${idx} OFFSET ${idx + 1}
|
||||||
""", *params)
|
""", *params, limit, offset)
|
||||||
|
|
||||||
|
pages = (total + limit - 1) // limit if limit > 0 else 1
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"total": len(rows),
|
"total": total,
|
||||||
|
"page": page,
|
||||||
|
"limit": limit,
|
||||||
|
"pages": pages,
|
||||||
"texts": [
|
"texts": [
|
||||||
{
|
{
|
||||||
"id": r["id"],
|
"id": r["id"],
|
||||||
|
|||||||
Reference in New Issue
Block a user