feat: пагинация для /words/all + GET texts/all + DELETE text + глобальные дубликаты
This commit is contained in:
+36
-10
@@ -18,6 +18,8 @@ CRUD слов:
|
||||
- POST /admin/wordsearch/words — добавить слово
|
||||
- PUT /admin/wordsearch/words/{word_id} — обновить слово
|
||||
- DELETE /admin/wordsearch/words/{word_id} — удалить слово
|
||||
|
||||
🔧 ОБНОВЛЕНО (30.09.2026): /words/all — пагинация + total.
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
@@ -632,24 +634,38 @@ async def list_all_csv_words(
|
||||
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": 2446, # всего под фильтром
|
||||
"page": 1, # текущая страница
|
||||
"limit": 50, # размер страницы
|
||||
"pages": 49, # всего страниц
|
||||
"words": [...], # слова текущей страницы
|
||||
}
|
||||
"""
|
||||
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:
|
||||
@@ -668,18 +684,28 @@ async def list_all_csv_words(
|
||||
idx += 1
|
||||
|
||||
where = ("WHERE " + " AND ".join(conditions)) if conditions else ""
|
||||
params.append(limit)
|
||||
|
||||
# Общее количество
|
||||
total = await conn.fetchval(f"""
|
||||
SELECT COUNT(*) FROM csv_words {where}
|
||||
""", *params) or 0
|
||||
|
||||
# Страница
|
||||
rows = await conn.fetch(f"""
|
||||
SELECT id, level_code, word_pl, translation_ru, translation_uk, translation_en
|
||||
FROM csv_words
|
||||
{where}
|
||||
ORDER BY level_code, word_pl
|
||||
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,
|
||||
"words": [
|
||||
{
|
||||
"id": r["id"],
|
||||
|
||||
Reference in New Issue
Block a user