# Path: restapi/utils/decorators.py
# def crossdomain(func, allow_origin=None, allow_headers=None, max_age=None):
#     """
#     Enable CORS.
#     @param func: wrapped function
#     @param allow_origin: specify origin
#     @param allow_headers: allow headers
#     @param max_age: define max age
#     @return: function
#     """
#     if not allow_origin:
#         allow_origin = "*"
#     if not allow_headers:
#         allow_headers = "content-type, accept"
#     if not max_age:
#         max_age = 60
# 
#     @wraps(func)
#     def wrapper(*args, **kwargs):
#         response = func(*args, **kwargs)
#         cors_headers = {
#             "Access-Control-Allow-Origin": allow_origin,
#             "Access-Control-Allow-Methods": func.__name__.upper(),
#             "Access-Control-Allow-Headers": allow_headers,
#             "Access-Control-Max-Age": max_age,
#         }
#         if isinstance(response, tuple):
#             if len(response) == 3:
#                 headers = response[-1]
#             else:
#                 headers = {}
#             headers.update(cors_headers)
#             return response[0], response[1], headers
#         else:
#             return response, 200, cors_headers
#     return wrapper
# 
# Path: restapi/modules/responses.py
# def create_single_object_response(status, object, object_naming_singular):
# def create_multiple_object_response(status, list_of_objects, objects_naming_plural):
# 
# Path: restapi/modules/errors.py
# def log_exception(sender, exception, **extra):
# def error_incorrect_version(version):
# def error_object_not_found():
# def error_commit_error(ex):
# 
# Path: restapi/modules/statuscodes.py
# HTTP_OK = 200
# HTTP_CREATED = 201
# HTTP_ACCEPTED = 202
# HTTP_NON_AUTH_INFO = 203
# HTTP_NO_CONTENT = 204
# HTTP_RESET = 205
# HTTP_PARTIAL_CONTENT = 206
# HTTP_BAD_REQUEST = 400
# HTTP_UNAUTHORIZED = 401
# HTTP_PAYMENT_REQUIRED = 402
# HTTP_FORBIDDEN = 403
# HTTP_NOT_FOUND = 404
# HTTP_METHOD_NOT_ALLOWED = 405
# HTTP_NOT_ACCEPTABLE = 406
# HTTP_PROXY_AUTH_REQUIRED = 407
# HTTP_REQUEST_TIMEOUT = 408
# HTTP_CONFLICT = 409
# HTTP_GONE = 410
# HTTP_REQ_TO_LARGE = 413
# HTTP_REQ_TO_LONG = 414
# HTTP_UNSUPPORTED_MEDIA_TYPE = 415
# HTTP_TOO_MANY_REQUESTS = 429
# HTTP_INTERNAL_ERROR = 500
# HTTP_NOT_IMPLEMENTED = 501
# HTTP_BAD_GATEWAY = 502
# HTTP_SERVICE_UNAVAILABLE = 503
# HTTP_GATEWAY_TIMEOUT = 504
# HTTP_VERSION_UNSUPPORTED = 505
# 
# Path: restapi/components/auth/decorators.py
# def require_app_key(f):
#     """
#     @param f: flask function
#     @return: decorator, return the wrapped function or abort json object.
#     """
# 
#     @wraps(f)
#     def decorated(*args, **kwargs):
#         if match_api_keys(request.args.get('key'), request.remote_addr):
#             return f(*args, **kwargs)
#         else:
#             with log_to_file:
#                 log.warning("Unauthorized address trying to use API: " + request.remote_addr)
#             abort(401)
# 
#     return decorated
# 
# Path: restapi/modules/cakes/models.py
# class Cake(BaseModel):
# class CakeSerializer(Serializer):
#     class Meta:
#     def __init__(self, cakename, bakername, price):
#     def as_dict(self):
#     def __repr__(self):
#     def format_price_range(cake):


import math
from flask import Blueprint, jsonify, request
from restapi.utils.decorators import crossdomain
from restapi.modules import responses, errors, statuscodes
from restapi.components.auth.decorators import require_app_key
from restapi.modules.cakes.models import Cake, db, CakeSerializer
from sqlalchemy.exc import IntegrityError

        if cake is None:
            return jsonify(errors.error_object_not_found()), statuscodes.HTTP_NOT_FOUND

        db.session.delete(cake)

        try:
            db.session.commit()
        except IntegrityError as ex:
            return jsonify(errors.error_commit_error(ex)), statuscodes.HTTP_INTERNAL_ERROR

        return jsonify(
            responses.create_single_object_response('success', CakeSerializer(cake).data, "cake")), statuscodes.HTTP_OK

    # Unsupported Versions
    else:
        return jsonify(errors.error_incorrect_version(version)), statuscodes.HTTP_VERSION_UNSUPPORTED


@mod.route('/', methods=['GET'])
@crossdomain
def get_all_cakes(version):
    """
    Controller for API Function that gets all cakes in the database.
    @return: Response and HTTP code
    """

    # API Version 1.X
    if math.floor(version) == 1:


# Path: restapi/utils/decorators.py
# def crossdomain(func, allow_origin=None, allow_headers=None, max_age=None):
#     """
#     Enable CORS.
#     @param func: wrapped function
#     @param allow_origin: specify origin
#     @param allow_headers: allow headers
#     @param max_age: define max age
#     @return: function
#     """
#     if not allow_origin:
#         allow_origin = "*"
#     if not allow_headers:
#         allow_headers = "content-type, accept"
#     if not max_age:
#         max_age = 60
# 
#     @wraps(func)
#     def wrapper(*args, **kwargs):
#         response = func(*args, **kwargs)
#         cors_headers = {
#             "Access-Control-Allow-Origin": allow_origin,
#             "Access-Control-Allow-Methods": func.__name__.upper(),
#             "Access-Control-Allow-Headers": allow_headers,
#             "Access-Control-Max-Age": max_age,
#         }
#         if isinstance(response, tuple):
#             if len(response) == 3:
#                 headers = response[-1]
#             else:
#                 headers = {}
#             headers.update(cors_headers)
#             return response[0], response[1], headers
#         else:
#             return response, 200, cors_headers
#     return wrapper
# 
# Path: restapi/modules/responses.py
# def create_single_object_response(status, object, object_naming_singular):
# def create_multiple_object_response(status, list_of_objects, objects_naming_plural):
# 
# Path: restapi/modules/errors.py
# def log_exception(sender, exception, **extra):
# def error_incorrect_version(version):
# def error_object_not_found():
# def error_commit_error(ex):
# 
# Path: restapi/modules/statuscodes.py
# HTTP_OK = 200
# HTTP_CREATED = 201
# HTTP_ACCEPTED = 202
# HTTP_NON_AUTH_INFO = 203
# HTTP_NO_CONTENT = 204
# HTTP_RESET = 205
# HTTP_PARTIAL_CONTENT = 206
# HTTP_BAD_REQUEST = 400
# HTTP_UNAUTHORIZED = 401
# HTTP_PAYMENT_REQUIRED = 402
# HTTP_FORBIDDEN = 403
# HTTP_NOT_FOUND = 404
# HTTP_METHOD_NOT_ALLOWED = 405
# HTTP_NOT_ACCEPTABLE = 406
# HTTP_PROXY_AUTH_REQUIRED = 407
# HTTP_REQUEST_TIMEOUT = 408
# HTTP_CONFLICT = 409
# HTTP_GONE = 410
# HTTP_REQ_TO_LARGE = 413
# HTTP_REQ_TO_LONG = 414
# HTTP_UNSUPPORTED_MEDIA_TYPE = 415
# HTTP_TOO_MANY_REQUESTS = 429
# HTTP_INTERNAL_ERROR = 500
# HTTP_NOT_IMPLEMENTED = 501
# HTTP_BAD_GATEWAY = 502
# HTTP_SERVICE_UNAVAILABLE = 503
# HTTP_GATEWAY_TIMEOUT = 504
# HTTP_VERSION_UNSUPPORTED = 505
# 
# Path: restapi/components/auth/decorators.py
# def require_app_key(f):
#     """
#     @param f: flask function
#     @return: decorator, return the wrapped function or abort json object.
#     """
# 
#     @wraps(f)
#     def decorated(*args, **kwargs):
#         if match_api_keys(request.args.get('key'), request.remote_addr):
#             return f(*args, **kwargs)
#         else:
#             with log_to_file:
#                 log.warning("Unauthorized address trying to use API: " + request.remote_addr)
#             abort(401)
# 
#     return decorated
# 
# Path: restapi/modules/cakes/models.py
# class Cake(BaseModel):
# class CakeSerializer(Serializer):
#     class Meta:
#     def __init__(self, cakename, bakername, price):
#     def as_dict(self):
#     def __repr__(self):
#     def format_price_range(cake):


# Path: restapi/modules/cakes/controllers.py
import math
from flask import Blueprint, jsonify, request
from restapi.utils.decorators import crossdomain
from restapi.modules import responses, errors, statuscodes
from restapi.components.auth.decorators import require_app_key
from restapi.modules.cakes.models import Cake, db, CakeSerializer
from sqlalchemy.exc import IntegrityError


        if cake is None:
            return jsonify(errors.error_object_not_found()), statuscodes.HTTP_NOT_FOUND

        db.session.delete(cake)

        try:
            db.session.commit()
        except IntegrityError as ex:
            return jsonify(errors.error_commit_error(ex)), statuscodes.HTTP_INTERNAL_ERROR

        return jsonify(
            responses.create_single_object_response('success', CakeSerializer(cake).data, "cake")), statuscodes.HTTP_OK

    # Unsupported Versions
    else:
        return jsonify(errors.error_incorrect_version(version)), statuscodes.HTTP_VERSION_UNSUPPORTED


@mod.route('/', methods=['GET'])
@crossdomain
def get_all_cakes(version):
    """
    Controller for API Function that gets all cakes in the database.
    @return: Response and HTTP code
    """

    # API Version 1.X
    if math.floor(version) == 1:


        cakes = Cake.query.all()