bash_problem_search/app/utils/response_wrapper.py

17 lines
567 B
Python

# app/utils/response_wrapper.py
from functools import wraps
from fastapi.responses import JSONResponse
from app.schemas.response import ResponseModel
import inspect
def standard_response(func):
@wraps(func)
async def wrapper(*args, **kwargs):
if inspect.iscoroutinefunction(func):
result = await func(*args, **kwargs)
else:
result = func(*args, **kwargs)
response = ResponseModel(msg="success", success=True, data=result, code=200)
return JSONResponse(content=response.model_dump())
return wrapper