Spaces:
Running
Running
Commit
·
2fa91ca
1
Parent(s):
36c3749
update
Browse files
app/api/notes/internal_notes.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, HTTPException
|
| 2 |
+
from pydantic import BaseModel, Field
|
| 3 |
+
from typing import Optional, List, Dict, Any
|
| 4 |
+
|
| 5 |
+
from app.services.note_store import get_note, update_note
|
| 6 |
+
from app.utils.time import now_ts
|
| 7 |
+
|
| 8 |
+
router = APIRouter(
|
| 9 |
+
prefix="/internal/notes",
|
| 10 |
+
tags=["internal-notes"],
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
class InternalUpdateNoteRequest(BaseModel):
|
| 14 |
+
status: Optional[str] = Field(
|
| 15 |
+
None,
|
| 16 |
+
description="processing | transcribed | error | failed",
|
| 17 |
+
)
|
| 18 |
+
raw_text: Optional[str] = None
|
| 19 |
+
metadata: Optional[Dict[str, Any]] = None
|
| 20 |
+
|
| 21 |
+
# pipeline triggers
|
| 22 |
+
generate: Optional[List[str]] = None
|
| 23 |
+
|
| 24 |
+
@router.patch("/{note_id}")
|
| 25 |
+
def update_note_internal(note_id: str, req: InternalUpdateNoteRequest):
|
| 26 |
+
note = get_note(note_id)
|
| 27 |
+
if not note:
|
| 28 |
+
raise HTTPException(status_code=404, detail="Note not found")
|
| 29 |
+
|
| 30 |
+
updates = req.dict(exclude_unset=True)
|
| 31 |
+
|
| 32 |
+
# cập nhật timestamp hệ thống
|
| 33 |
+
updates["updated_at"] = now_ts()
|
| 34 |
+
|
| 35 |
+
update_note(note_id, updates)
|
| 36 |
+
|
| 37 |
+
return {
|
| 38 |
+
"note_id": note_id,
|
| 39 |
+
"updated": True,
|
| 40 |
+
"fields": list(updates.keys()),
|
| 41 |
+
}
|
app/api/notes/notes_update.py
CHANGED
|
@@ -7,24 +7,27 @@ from app.utils.time import now_ts
|
|
| 7 |
|
| 8 |
router = APIRouter(prefix="/notes", tags=["notes"])
|
| 9 |
|
| 10 |
-
|
| 11 |
class UpdateNoteRequest(BaseModel):
|
| 12 |
folder_id: Optional[str] = None
|
| 13 |
title: Optional[str] = None
|
| 14 |
|
| 15 |
-
|
| 16 |
@router.patch("/{note_id}")
|
| 17 |
def update_note_api(note_id: str, req: UpdateNoteRequest):
|
| 18 |
note = get_note(note_id)
|
| 19 |
if not note:
|
| 20 |
-
raise HTTPException(404, "Note not found")
|
| 21 |
|
| 22 |
updates = req.dict(exclude_unset=True)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
updates["updated_at"] = now_ts()
|
| 28 |
|
| 29 |
update_note(note_id, updates)
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
router = APIRouter(prefix="/notes", tags=["notes"])
|
| 9 |
|
|
|
|
| 10 |
class UpdateNoteRequest(BaseModel):
|
| 11 |
folder_id: Optional[str] = None
|
| 12 |
title: Optional[str] = None
|
| 13 |
|
|
|
|
| 14 |
@router.patch("/{note_id}")
|
| 15 |
def update_note_api(note_id: str, req: UpdateNoteRequest):
|
| 16 |
note = get_note(note_id)
|
| 17 |
if not note:
|
| 18 |
+
raise HTTPException(status_code=404, detail="Note not found")
|
| 19 |
|
| 20 |
updates = req.dict(exclude_unset=True)
|
| 21 |
|
| 22 |
+
if not updates:
|
| 23 |
+
return {"note_id": note_id, "updated": False}
|
| 24 |
|
| 25 |
updates["updated_at"] = now_ts()
|
| 26 |
|
| 27 |
update_note(note_id, updates)
|
| 28 |
+
|
| 29 |
+
return {
|
| 30 |
+
"note_id": note_id,
|
| 31 |
+
"updated": True,
|
| 32 |
+
"fields": list(updates.keys()),
|
| 33 |
+
}
|