freeleaps-service-hub/app/central_storage/backend/business/document_manager.py

37 lines
1.4 KiB
Python

from app.central_storage.backend.services.document_service import DocumentService
from app.central_storage.backend.models.models import MediaType, DataFormat
class DocumentManager:
def __init__(self) -> None:
self.document_service = DocumentService()
async def retrieve_document_info(self, document_id: str):
await self.document_service.load_document(document_id=document_id)
download_link = (
await self.document_service.fetch_document_file_as_http_download()
)
file_name = self.document_service.get_file_name()
return {
"file_name": file_name,
"file_download_url": download_link,
}
async def upload_file(
self, associated_with: str, file_name: str, file_data: bytes
) -> bool:
await self.document_service.new_document(
file_name=file_name,
# This 'UNKNOWN' will make the document manager decide the media type from file name
media_type=MediaType.UNKNOWN,
data_format=DataFormat.RAW,
created_by=associated_with,
)
return await self.document_service.save_document_file(file_data) or None
# TODO: This should go to Freeleaps App
# add_doc = await self.attachment_service.add_document_to_request(
# request_id, document_id
# )
# await self.proposal_store.update_latest_proposal_with_documents(request_id)