Exemplo n.º 1
0
def login() -> Dict:
    """
       API to login user.
       :return: JSON response
    """
    payload = request.get_json()
    error, result = get_auth_token(**payload)
    return success(data=result) if not error else failure(message=error)
Exemplo n.º 2
0
def signup() -> Dict:
    """
       API to Sign up with a new user.
       :return: JSON response
    """
    payload = request.get_json()
    error, result = create_user(**payload)
    return success(data=result) if not error else failure(message=error)
Exemplo n.º 3
0
def get_all_items() -> Dict:
    """
    This method will return all
    the items available.
    :return: JSON response
    """
    filters = request.args
    error, items = fetch_all(filters)
    return success(data=items) if not error else failure(message=error)
Exemplo n.º 4
0
def get_single_item(obj_id) -> Dict:
    """
    This method will return the
    single item with given object id.
    :param obj_id: Object ID
    :return: JSON response
    """
    error, item = fetch_single(obj_id)
    return success(data=item) if not error else failure(message=error)
Exemplo n.º 5
0
def token_error_callback(error: Union[str, dict]) -> Dict:
    """
    This method returns a callback error
    if the token is expired, invalid
    or is unauthorized.
    :param error: Any kind of error string
    :return: A JSON response containing
    essential information with an error message.
    """
    error = error if isinstance(error, str) else "Token expired"
    return failure(message=error, status_code=401)