from flask import Blueprint
from flask import Flask, json, Response, request, abort
from flask import jsonify, make_response

# Add new blueprints here
if __package__ is None or __package__ == '':
    # uses current directory visibility
    import customer_table_client
    from custom_logger import setup_logger
else:
    # uses current package visibility
    from flaskr import customer_table_client
    from flaskr.custom_logger import setup_logger

# Set up the custom logger and the Blueprint
logger = setup_logger(__name__)
customer_module = Blueprint('customers', __name__)

logger.info("Intialized customer routes")

# Allow the default route to return a health check
@customer_module.route('/')
def health_check():
    return "This a health check. Customer Management Service is up and running."

# Get all customers
@customer_module.route('/customers')
def get_all_customers():
    try:
        service_response = customer_table_client.get_all_customers()
    except Exception as e:
예제 #2
0
import os
import ujson
import falcon
import requests
from custom_logger import setup_logger
from datetime import datetime
from decouple import config
from pprint import pprint, pformat

logger = setup_logger('ProductResource Logger')

THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
my_file = os.path.join(THIS_FOLDER, 'products.json')

# load products static db from json file
with open(my_file) as f:
    products = ujson.load(f)


class ProductResource(object):
    def on_get(self, req, resp):

        try:
            logger.info("Performing get all products...")

            resp.body = ujson.dumps({'products': products})
            resp.status = falcon.HTTP_200

        except Exception as e:

            logger.error(e, exc_info=True)