"""Application Handlers. Requests are redirected to handlers, which are responsible for getting information from the URL and passing it down to the logic layer. The way each layer talks to each other is through Response objects which defines the type status of the data and the data itself. Please note: the Orchard uses the term handlers over views as convention for clarity See: oto.response for more details. """ from flask import g from flask import jsonify from flask import request from oto import response from oto.adaptors.flask import flaskify from backend import config from backend.api import app from backend.logic import vendor as vendor_logic # DO NOT IMPORT ANY MODELS @app.route(config.HEALTH_CHECK, methods=['GET']) def health(): """Check the health of the application.""" return jsonify({'status': 'ok'}) @app.route('/vendor/', methods=['GET']) #@handlers_util.get_headers def get_vendor_details(vendor_id): """Fetch a single vendor's details. Returns: flask.Response: on successful, 200 status with JSON body. """ result = vendor_logic.get_vendor_details(vendor_id) return flaskify(result) @app.route('/vendors', methods=['GET']) #@handlers_util.get_headers def get_vendor_list_details(): """Fetch a single vendor's details. Returns: flask.Response: on successful, 200 status with JSON body. """ result = vendor_logic.get_multiple_vendor_details() return flaskify(result) @app.errorhandler(500) def exception_handler(error): """Default handler when uncaught exception is raised. Note: Exception will also be sent to Sentry if config.SENTRY is set. Returns: flask.Response: A 500 response with JSON 'code' & 'message' payload. """ message = ( 'The server encountered an internal error ' 'and was unable to complete your request.') g.log.exception(error) return flaskify(response.create_fatal_response(message))