from fastapi import APIRouter, HTTPException from pydantic import BaseModel, Field from typing import Optional, List, Dict, Any from app.services.note_store import get_note, update_note from app.utils.time import now_ts router = APIRouter( prefix="/internal/notes", tags=["internal-notes"], ) class InternalUpdateNoteRequest(BaseModel): status: Optional[str] = Field( None, description="processing | transcribed | error | failed", ) raw_text: Optional[str] = None metadata: Optional[Dict[str, Any]] = None # pipeline triggers generate: Optional[List[str]] = None @router.patch("/{note_id}") def update_note_internal(note_id: str, req: InternalUpdateNoteRequest): note = get_note(note_id) if not note: raise HTTPException(status_code=404, detail="Note not found") updates = req.dict(exclude_unset=True) # cập nhật timestamp hệ thống updates["updated_at"] = now_ts() update_note(note_id, updates) return { "note_id": note_id, "updated": True, "fields": list(updates.keys()), }