NoteServicesAPI / app /api /notes /notes_update.py
bichnhan2701's picture
Update note services logic
7402e0f
raw
history blame
796 Bytes
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from typing import Optional
from app.services.note_store import get_note, update_note
from app.utils.time import now_ts
router = APIRouter(prefix="/notes", tags=["notes"])
class UpdateNoteRequest(BaseModel):
folder_id: Optional[str] = None
title: Optional[str] = None
@router.patch("/{note_id}")
def update_note_api(note_id: str, req: UpdateNoteRequest):
note = get_note(note_id)
if not note:
raise HTTPException(404, "Note not found")
updates = req.dict(exclude_unset=True)
# ❗ Không cho client sửa status trực tiếp
updates.pop("status", None)
updates["updated_at"] = now_ts()
update_note(note_id, updates)
return {"note_id": note_id, "updated": True}