Spaces:
Runtime error
Runtime error
File size: 827 Bytes
af7af6c eb474ee a3aa6c1 eb474ee af7af6c eb474ee af7af6c eb474ee |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from fastapi import APIRouter, HTTPException, Request
from src.config import logger
from src.services import FileService
from src.schemas import InsertFileSchema
class FileController:
def __init__(self):
self.service = FileService
self.api_router = APIRouter()
self.api_router.add_api_route("/files", self.insert_file, methods=["POST"])
async def insert_file(self, request: Request, data: InsertFileSchema):
try:
user_id = request.state.user["user_id"]
file = data.file
async with self.service() as service:
return await service.insert_file(file=file, user_id=user_id)
except Exception as e:
logger.error(f"Error while inserting file: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
|