change document api to uset get by id

This commit is contained in:
phernandez
2024-12-21 23:46:05 -06:00
parent 0f88c6bc6b
commit 3541c2873d
3 changed files with 57 additions and 33 deletions
+5 -5
View File
@@ -49,21 +49,21 @@ async def list_documents(
return [DocumentCreateResponse.model_validate(doc.__dict__) for doc in documents]
@router.get("/{path:path}", response_model=DocumentResponse)
@router.get("/{id:int}", response_model=DocumentResponse)
async def get_document(
path: str,
id: int,
service: DocumentServiceDep,
) -> DocumentResponse:
"""Get a document by path."""
"""Get a document by ID."""
try:
document, content = await service.read_document(path)
document, content = await service.read_document_by_id(id)
doc_dict = document.__dict__ | {"content": content}
response = DocumentResponse.model_validate(doc_dict)
return response
except DocumentNotFoundError:
raise HTTPException(
status_code=404,
detail=f"Document not found: {path}"
detail=f"Document not found: {id}"
)
except DocumentWriteError as e:
raise HTTPException(status_code=400, detail=str(e))