Reformats Endpoints Configuration and Start Script
This commit is contained in:
@@ -1,30 +1,2 @@
|
||||
from storage_service.config.config_allowed_origins import get_allowed_origins
|
||||
from storage_service.controller.health_checker_controller import health_router
|
||||
from storage_service.controller.storage_controller import s3_router
|
||||
from storage_service.utils.exception_handler import (
|
||||
http_exception_handler,
|
||||
validation_exception_handler,
|
||||
)
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
app.add_exception_handler(HTTPException, http_exception_handler)
|
||||
app.add_exception_handler(RequestValidationError, validation_exception_handler)
|
||||
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=get_allowed_origins(),
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(s3_router)
|
||||
app.include_router(health_router)
|
||||
from .health_checker_controller import router as health_router
|
||||
from .storage_controller import router as storage_router
|
||||
|
||||
@@ -5,11 +5,11 @@ from storage_service.model.health_check.health_check_response import (
|
||||
from fastapi import APIRouter
|
||||
from fastapi_utils.cbv import cbv
|
||||
|
||||
health_router = APIRouter(tags=["health"])
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@cbv(health_router)
|
||||
@cbv(router)
|
||||
class HealthCheckerController:
|
||||
@health_router.get("/health", status_code=200)
|
||||
@router.get("/health", status_code=200)
|
||||
def health(self) -> HealthCheckResponse:
|
||||
return HealthCheckResponse(status="healthy")
|
||||
|
||||
@@ -20,17 +20,17 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi_utils.cbv import cbv
|
||||
from rq import Queue
|
||||
|
||||
s3_router = APIRouter(tags=["storage"])
|
||||
router = APIRouter(tags=["storage"])
|
||||
|
||||
|
||||
@cbv(s3_router)
|
||||
@cbv(router)
|
||||
class StorageController:
|
||||
queue: Queue = Depends(dependency_queue, use_cache=True)
|
||||
storage_service: StorageService = Depends(
|
||||
dependency_storage_service, use_cache=True
|
||||
)
|
||||
|
||||
@s3_router.post("/file", status_code=200)
|
||||
@router.post("/file", status_code=200)
|
||||
def new_file_url(self, new_file_request: NewFileURLRequest) -> SignedUrlResponse:
|
||||
hashed_file_name = generate_file_hash(
|
||||
new_file_request.file_key, new_file_request.file_postfix
|
||||
@@ -40,7 +40,7 @@ class StorageController:
|
||||
hashed_file_name, new_file_request.file_type
|
||||
)
|
||||
|
||||
@s3_router.get("/file", status_code=200)
|
||||
@router.get("/file", status_code=200)
|
||||
def file_url(self, file_key: str, file_postfix: str) -> SignedUrlResponse:
|
||||
try:
|
||||
return self.storage_service.get_temp_read_link(
|
||||
@@ -49,13 +49,13 @@ class StorageController:
|
||||
except Exception as _:
|
||||
raise FileNotFoundException("File not found")
|
||||
|
||||
@s3_router.delete("/file", status_code=204)
|
||||
@router.delete("/file", status_code=204)
|
||||
def delete_file(self, file_key: str, file_postfix: str):
|
||||
return self.storage_service.delete_file(
|
||||
generate_file_hash(file_key, file_postfix)
|
||||
)
|
||||
|
||||
@s3_router.post("/file/process", status_code=200)
|
||||
@router.post("/file/process", status_code=200)
|
||||
def process_file(self, process_file_request: ProcessFileRequest):
|
||||
self.queue.enqueue(
|
||||
storage_file_worker,
|
||||
|
||||
Reference in New Issue
Block a user