This commit is contained in:
Team3
2026-06-01 18:22:13 +02:00
parent b591897fd6
commit e7af2b1150
5 changed files with 165 additions and 12 deletions

View File

@@ -43,6 +43,15 @@ CREATE TABLE IF NOT EXISTS baustein_suggestions (
)
"""
CREATE_PROGRESS = """
CREATE TABLE IF NOT EXISTS guide_progress (
guide_id TEXT NOT NULL,
chapter TEXT NOT NULL,
created_at TEXT NOT NULL,
PRIMARY KEY (guide_id, chapter)
)
"""
_db: aiosqlite.Connection | None = None
@@ -59,6 +68,7 @@ async def init_db():
await db.execute(CREATE_GUIDES)
await db.execute(CREATE_BAUSTEINE)
await db.execute(CREATE_SUGGESTIONS)
await db.execute(CREATE_PROGRESS)
cursor = await db.execute("PRAGMA table_info(guides)")
columns = {row[1] for row in await cursor.fetchall()}
if "instructions" not in columns:
@@ -249,3 +259,35 @@ async def delete_pending_suggestions(topic: str) -> None:
"DELETE FROM baustein_suggestions WHERE topic = ? AND status = 'pending'", (topic,)
)
await db.commit()
# --- Kapitel-Fortschritt ---
async def list_progress(guide_id: str) -> list[str]:
db = await get_db()
cursor = await db.execute(
"SELECT chapter FROM guide_progress WHERE guide_id = ?", (guide_id,)
)
rows = await cursor.fetchall()
return [row[0] for row in rows]
async def set_progress(guide_id: str, chapter: str, done: bool) -> None:
from datetime import datetime, timezone
db = await get_db()
if done:
await db.execute(
"INSERT OR IGNORE INTO guide_progress (guide_id, chapter, created_at) VALUES (?, ?, ?)",
(guide_id, chapter, datetime.now(timezone.utc).isoformat()),
)
else:
await db.execute(
"DELETE FROM guide_progress WHERE guide_id = ? AND chapter = ?", (guide_id, chapter)
)
await db.commit()
async def delete_progress(guide_id: str) -> None:
db = await get_db()
await db.execute("DELETE FROM guide_progress WHERE guide_id = ?", (guide_id,))
await db.commit()