"""FlowDeck — Notes markdown par projet.""" from __future__ import annotations import logging from fastapi import APIRouter, Request from fastapi.responses import HTMLResponse from app.db import get_conn logger = logging.getLogger(__name__) router = APIRouter(tags=["notes"], prefix="/notes") @router.get("/{owner}/{repo}", response_class=HTMLResponse) async def get_notes(request: Request, owner: str, repo: str): with get_conn() as conn: row = conn.execute( "SELECT content FROM notes WHERE project_owner=? AND project_name=? AND title='Notes'", (owner, repo), ).fetchone() content = row["content"] if row else "" from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader("app/templates")) template = env.get_template("notes.html") return template.render(request=request, owner=owner, repo=repo, content=content) @router.post("/{owner}/{repo}", response_class=HTMLResponse) async def save_notes(request: Request, owner: str, repo: str): form = await request.form() content = form.get("content", "") with get_conn() as conn: conn.execute( """INSERT INTO notes (project_owner, project_name, title, content, updated_at) VALUES (?, ?, 'Notes', ?, CURRENT_TIMESTAMP) ON CONFLICT(project_owner, project_name, title) DO UPDATE SET content=excluded.content, updated_at=CURRENT_TIMESTAMP""", (owner, repo, content), ) conn.commit() from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader("app/templates")) template = env.get_template("notes.html") return template.render(request=request, owner=owner, repo=repo, content=content)