[Eva] B5.1: /next — убрать фильтр по уровню (единый пул)

This commit is contained in:
2026-10-16 11:58:50 +00:00
parent 965d5d2503
commit 1df1119d11
+5 -7
View File
@@ -100,25 +100,23 @@ async def get_next_sentence(request: Request):
pool = await get_pool() pool = await get_pool()
async with pool.acquire() as conn: async with pool.acquire() as conn:
user = await conn.fetchrow( user = await conn.fetchrow(
"SELECT app_language, current_level, difficulty FROM users WHERE telegram_id = $1", telegram_id "SELECT app_language, difficulty FROM users WHERE telegram_id = $1", telegram_id
) )
if not user: if not user:
raise HTTPException(401, "User not registered") raise HTTPException(401, "User not registered")
lang = user["app_language"] or "pl" lang = user["app_language"] or "pl"
current_level = user["current_level"] or "A1"
difficulty = user["difficulty"] or "medium" difficulty = user["difficulty"] or "medium"
# Находим случайное непройденное предложение нужного уровня # Находим случайное непройденное предложение (единый пул)
row = await conn.fetchrow(""" row = await conn.fetchrow("""
SELECT s.* FROM sentences s SELECT s.* FROM sentences s
WHERE s.level = $1 WHERE s.id NOT IN (
AND s.id NOT IN ( SELECT sentence_id FROM sentence_progress WHERE user_id = $1 AND completed_at IS NOT NULL
SELECT sentence_id FROM sentence_progress WHERE user_id = $2 AND completed_at IS NOT NULL
) )
ORDER BY RANDOM() ORDER BY RANDOM()
LIMIT 1 LIMIT 1
""", current_level, telegram_id) """, telegram_id)
if not row: if not row:
return {"completed": True, "message": "All sentences completed!"} return {"completed": True, "message": "All sentences completed!"}