🔧 ФИКС: completed/already_completed не путают подсказку с завершением
Проблема: hints.py создаёт строку user_progress с score=0, completed_at=NULL (пометка о подсказке). Но: - get_level: completed = progress is not None → показывал 'Уже пройдено!' - complete_level: already_completed = True при любой строке → last_completed_level НЕ обновлялся → следующие уровни недоступны Фикс: completed / already_completed = completed_at IS NOT NULL ИЛИ score > 0. Строка от подсказки больше не считается пройденным уровнем.
This commit is contained in:
+30
-3
@@ -113,6 +113,18 @@ async def get_level(request: Request, level_number: int):
|
||||
if isinstance(word_paths, str):
|
||||
word_paths = json.loads(word_paths)
|
||||
|
||||
# 🔧 ФИКС (25.09.2026): completed_detects_hint_row —
|
||||
# раньше completed = progress is not None. Но hints.py создаёт
|
||||
# строку при подсказке (score=0, completed_at=NULL) — это НЕ завершение.
|
||||
# Теперь: completed = completed_at IS NOT NULL OR score > 0.
|
||||
is_completed = (
|
||||
progress is not None
|
||||
and (
|
||||
progress["completed_at"] is not None
|
||||
or (progress["score"] or 0) > 0
|
||||
)
|
||||
)
|
||||
|
||||
return {
|
||||
"level": {
|
||||
"id": level["id"],
|
||||
@@ -124,7 +136,7 @@ async def get_level(request: Request, level_number: int):
|
||||
},
|
||||
"words": word_list,
|
||||
"progress": {
|
||||
"completed": progress is not None,
|
||||
"completed": is_completed,
|
||||
"hints_used": progress["hints_used"] if progress else 0,
|
||||
"score": progress["score"] if progress else 0,
|
||||
},
|
||||
@@ -277,12 +289,27 @@ async def complete_level(request: Request):
|
||||
if level_name != (user["current_level"] or "A1"):
|
||||
raise HTTPException(403, "This level does not belong to your current level")
|
||||
|
||||
# 🔧 ФИКС (25.09.2026): already_completed_detects_hint_row —
|
||||
# раньше already_completed = True при ЛЮБОЙ строке user_progress.
|
||||
# Но hints.py создаёт строку при подсказке (score=0,
|
||||
# completed_at=NULL) — это НЕ завершение. Тогда complete_level
|
||||
# считал уровень пройденным и НЕ обновлял last_completed_level.
|
||||
# Теперь: уже пройден только если completed_at IS NOT NULL
|
||||
# ИЛИ score > 0.
|
||||
existing_progress = await conn.fetchrow(
|
||||
"SELECT score FROM user_progress WHERE user_id = $1 AND level_id = $2",
|
||||
"SELECT score, completed_at FROM user_progress WHERE user_id = $1 AND level_id = $2",
|
||||
telegram_id, level_id
|
||||
)
|
||||
|
||||
if existing_progress:
|
||||
is_really_completed = (
|
||||
existing_progress is not None
|
||||
and (
|
||||
existing_progress["completed_at"] is not None
|
||||
or (existing_progress["score"] or 0) > 0
|
||||
)
|
||||
)
|
||||
|
||||
if is_really_completed:
|
||||
already_completed = True
|
||||
existing_score = existing_progress["score"]
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user