From eda9bbd92c10f602075d4b7b967d715baeaeb6d4 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Fri, 25 Sep 2026 17:47:44 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=D0=A4=D0=98=D0=9A=D0=A1:=20comp?= =?UTF-8?q?leted/already=5Fcompleted=20=D0=BD=D0=B5=20=D0=BF=D1=83=D1=82?= =?UTF-8?q?=D0=B0=D1=8E=D1=82=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=BA=D1=83=20=D1=81=20=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Проблема: 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. Строка от подсказки больше не считается пройденным уровнем. --- routers/game.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/routers/game.py b/routers/game.py index bcbe893..1a8093f 100644 --- a/routers/game.py +++ b/routers/game.py @@ -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: