A multipurpose python flask API server and administration SPA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

25 lines
643 B

from functools import wraps
from typing import Callable, Any
from flask import jsonify, Response
from atheneum.api.model import APIResponse
def return_json(func: Callable) -> Callable:
"""
If an Response object is not returned, jsonify the result and return it
:param func:
:return:
"""
@wraps(func)
def decorate(*args: list, **kwargs: dict) -> Any:
result = func(*args, **kwargs)
if isinstance(result, Response):
return result
if isinstance(result, APIResponse):
return jsonify(result.payload), result.status
return jsonify(result)
return decorate