"""Response helper for this app."""
from flask import jsonify


def json_response(code, message, payload):
    """Create a simple json response."""
    if payload is not None:
        data = {
            'message': message,
            'payload': payload,
        }
    else:
        data = {
            'message': message,
        }
    response = jsonify(data)
    response.status_code = code
    return response


def ok(message='', payload=None):
    """Response for HTTP `OK`."""
    return json_response(200, message, payload)


def created(message='', payload=None):
    """Response for HTTP `CREATED`."""
    return json_response(201, message, payload)


def bad_request(message='', payload=None):
    """Response for HTTP `BAD REQUEST`."""
    return json_response(400, message, payload)


def conflict(message='', payload=None):
    """Response for HTTP `CONFLICT`."""
    return json_response(409, message, payload)


def unauthorized(message="Unauthorized", payload=None):
    """Response for HTTP `UNAUTHORIZED`."""
    return json_response(401, message, payload)

@@ -81,32 +81,25 @@
 e(code, 
-message, payload
+data=None
 ):%0A    %22
@@ -138,196 +138,8 @@
 %22%22%22%0A
-    if payload is not None:%0A        data = %7B%0A            'message': message,%0A            'payload': payload,%0A        %7D%0A    else:%0A        data = %7B%0A            'message': message,%0A        %7D%0A
     
@@ -224,35 +224,20 @@
 %0Adef ok(
-message='', payload
+data
 =None):%0A
@@ -304,59 +304,32 @@
 00, 
-message, payload)%0A%0A%0Adef created(message='', payload
+data)%0A%0A%0Adef created(data
 =Non
@@ -401,32 +401,20 @@
 se(201, 
-message, payload
+data
 )%0A%0A%0Adef 
@@ -425,35 +425,20 @@
 request(
-message='', payload
+data
 =None):%0A
@@ -510,32 +510,20 @@
 se(400, 
-message, payload
+data
 )%0A%0A%0Adef 
@@ -535,27 +535,12 @@
 ict(
-message='', payload
+data
 =Non
@@ -613,32 +613,20 @@
 se(409, 
-message, payload
+data
 )%0A%0A%0Adef 
@@ -642,39 +642,12 @@
 zed(
-message=%22Unauthorized%22, payload
+data
 =Non
@@ -728,22 +728,10 @@
 01, 
-message, payload
+data
 )%0A

Change api response structure