Add tag editing and PDF preview to documents feature
Each document's tags are now editable inline: click Edit to enter a tag editor (Enter/comma to add, × to remove, Save to persist). The View button opens the PDF in a new browser tab via blob URL. Both features work through the existing proxy — no proxy changes needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ from app.deps import get_user_id
|
||||
from app.models.category import DocumentCategory
|
||||
from app.models.category_assignment import CategoryAssignment
|
||||
from app.models.document import Document
|
||||
from app.schemas.document import DocumentOut, DocumentStatusOut, DocumentTypeUpdate
|
||||
from app.schemas.document import DocumentOut, DocumentStatusOut, DocumentTypeUpdate, TagsUpdate
|
||||
from app.services.ai_client import AIServiceError, classify_document
|
||||
from app.services.config_reader import load_doc_config
|
||||
from app.services.storage import delete_file, get_upload_path, save_upload
|
||||
@@ -205,6 +205,28 @@ async def update_document_type(
|
||||
return _doc_with_categories(doc)
|
||||
|
||||
|
||||
@router.patch("/{doc_id}/tags", response_model=DocumentOut)
|
||||
async def update_document_tags(
|
||||
doc_id: str,
|
||||
body: TagsUpdate,
|
||||
user_id: str = Depends(get_user_id),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> DocumentOut:
|
||||
doc = await _get_user_doc(doc_id, user_id, db)
|
||||
# Normalise: strip whitespace, drop empties, deduplicate while preserving order
|
||||
seen: set[str] = set()
|
||||
clean: list[str] = []
|
||||
for t in body.tags:
|
||||
t = t.strip()
|
||||
if t and t.lower() not in seen:
|
||||
seen.add(t.lower())
|
||||
clean.append(t)
|
||||
doc.tags = json.dumps(clean)
|
||||
await db.commit()
|
||||
doc = await _get_user_doc(doc_id, user_id, db)
|
||||
return _doc_with_categories(doc)
|
||||
|
||||
|
||||
@router.delete("/{doc_id}", status_code=204)
|
||||
async def delete_document(
|
||||
doc_id: str,
|
||||
|
||||
Reference in New Issue
Block a user