38 lines
1.5 KiB
Python
38 lines
1.5 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, user_id) -> None:
|
|
self.user_id = user_id
|
|
self.document_service = DocumentService()
|
|
|
|
async def get_document_details_by_id(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_for_object(
|
|
self, object_id: 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=object_id,
|
|
)
|
|
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)
|