update
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -90,3 +90,12 @@ class GuideChatRequest(BaseModel):
|
||||
|
||||
class GuideChatResponse(BaseModel):
|
||||
reply: str
|
||||
|
||||
|
||||
class ProgressUpdate(BaseModel):
|
||||
chapter: str = Field(min_length=1, max_length=100)
|
||||
done: bool
|
||||
|
||||
|
||||
class ProgressResponse(BaseModel):
|
||||
chapters: list[str]
|
||||
|
||||
@@ -10,6 +10,7 @@ from database import (
|
||||
create_guide, delete_guide, get_guide, list_guides,
|
||||
create_baustein as db_create_baustein, list_bausteine, get_baustein, delete_baustein as db_delete_baustein,
|
||||
list_suggestions, get_suggestion, update_suggestion, delete_suggestion,
|
||||
list_progress, set_progress, delete_progress,
|
||||
)
|
||||
from generator import generate_guide, rework_guide, cancel_guide, generate_suggestions, generate_baustein_detail, rework_baustein, sort_bausteine, suggest_topics, chat_with_guide, is_suggestions_generating, is_sorting
|
||||
from models import (
|
||||
@@ -17,6 +18,7 @@ from models import (
|
||||
BausteinCreateRequest, BausteinReworkRequest, BausteinSortRequest, BausteinResponse, SuggestionResponse,
|
||||
TopicSuggestRequest, TopicSuggestion,
|
||||
GuideChatRequest, GuideChatResponse,
|
||||
ProgressUpdate, ProgressResponse,
|
||||
)
|
||||
from paths import final_paths
|
||||
|
||||
@@ -131,10 +133,28 @@ async def remove(guide_id: str):
|
||||
html_path, pdf_path = final_paths(guide["topic"], guide["format"])
|
||||
html_path.unlink(missing_ok=True)
|
||||
pdf_path.unlink(missing_ok=True)
|
||||
await delete_progress(guide_id)
|
||||
await delete_guide(guide_id)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/guides/{guide_id}/progress", response_model=ProgressResponse)
|
||||
async def get_progress(guide_id: str):
|
||||
guide = await get_guide(guide_id)
|
||||
if guide is None:
|
||||
raise HTTPException(404, "Guide nicht gefunden")
|
||||
return {"chapters": await list_progress(guide_id)}
|
||||
|
||||
|
||||
@router.post("/guides/{guide_id}/progress", response_model=ProgressResponse)
|
||||
async def update_progress(guide_id: str, req: ProgressUpdate):
|
||||
guide = await get_guide(guide_id)
|
||||
if guide is None:
|
||||
raise HTTPException(404, "Guide nicht gefunden")
|
||||
await set_progress(guide_id, req.chapter, req.done)
|
||||
return {"chapters": await list_progress(guide_id)}
|
||||
|
||||
|
||||
# --- Bausteine ---
|
||||
|
||||
@router.get("/bausteine", response_model=list[BausteinResponse])
|
||||
|
||||
Reference in New Issue
Block a user