Refactors Services and Initial Test Implementation

This commit is contained in:
2024-05-21 03:35:24 -03:00
parent b93faf11b3
commit 7eb4d5b64d
21 changed files with 336 additions and 34 deletions

View File

@@ -10,10 +10,11 @@ from storage_service.model.storage.process_file_request import (
)
from storage_service.model.storage.signed_url_response import SignedUrlResponse
from storage_service.service.storage.storage_service import StorageService
from storage_service.utils.file_name_hash import file_name_hash
from storage_service.utils.exceptions.file_not_found_exception import FileNotFoundException
from storage_service.utils.file.file_hash_generator import generate_file_hash
from storage_service.worker.storage_file_worker import storage_file_worker
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, HTTPException
from fastapi_utils.cbv import cbv
from rq import Queue
@@ -29,7 +30,7 @@ class StorageController:
@s3_router.post("/file", status_code=200)
def new_file_url(self, new_file_request: NewFileURLRequest) -> SignedUrlResponse:
hashed_file_name = file_name_hash(
hashed_file_name = generate_file_hash(
new_file_request.file_key, new_file_request.file_postfix
)
@@ -39,13 +40,16 @@ class StorageController:
@s3_router.get("/file", status_code=200)
def file_url(self, file_key: str, file_postfix: str) -> SignedUrlResponse:
return self.storage_service.get_temp_read_link(
file_name_hash(file_key, file_postfix)
)
try:
return self.storage_service.get_temp_read_link(
generate_file_hash(file_key, file_postfix)
)
except Exception as _:
raise FileNotFoundException("File not found")
@s3_router.delete("/file", status_code=204)
def delete_file(self, file_key: str, file_postfix: str):
return self.storage_service.delete_file(file_name_hash(file_key, file_postfix))
return self.storage_service.delete_file(generate_file_hash(file_key, file_postfix))
@s3_router.post("/file/process", status_code=200)
def process_file(self, process_file_request: ProcessFileRequest):