def get_purchase_orders_by_ship_date(event, context): """ Get list of purchase orders by ship_date range """ logger.debug('event: {}'.format(event)) params = get_path_parameters(event) min_ship_date = params['min_ship_date'] max_ship_date = params.get('max_ship_date', None) if hasattr(context, 'supplier_id'): supplier_id = context.supplier_id distributors = [] else: supplier_id = None distributor_id = context.distributor_id try: repo = DynamoRepository( region_name=os.environ['REGION'], dynamodb_local_endpoint=os.environ['DYNAMO_ENDPOINT']) except KeyError: repo = DynamoRepository(region_name=os.environ['REGION'], ) supplier_distributors = repo.get_all_distributor_suppliers( distributor_id) distributors = [ item['supplier_distributor_id'] for item in supplier_distributors ] items = context.repo.get_purchase_orders_by_ship_date_range( min_ship_date, max_ship_date, supplier_id, distributors) return {'statusCode': 200, 'body': json.dumps(items)}
def get_every_brand(event, context): """ Get all brands """ logger.debug('event: {}'.format(event)) if hasattr(context, 'supplier_id'): supplier = context.supplier_id else: distributor_id = context.distributor_id try: repo = DynamoRepository( region_name=os.environ['REGION'], dynamodb_local_endpoint=os.environ['DYNAMO_ENDPOINT'] ) except KeyError: repo = DynamoRepository( region_name=os.environ['REGION'], ) supplier_distributors = repo.get_all_distributor_suppliers(distributor_id) supplier = [item['supplier_id'] for item in supplier_distributors] items = context.repo.get_all_brands(supplier) return { 'statusCode': 200, 'body': json.dumps(items) }
def get_by_id(event, context): """ Get an count record by its id """ logger.debug('event: {}'.format(event)) params = get_path_parameters(event) if hasattr(context, 'supplier_id'): supplier_id = context.supplier_id distributors = [] else: supplier_id = None distributor_id = context.distributor_id try: repo = DynamoRepository( region_name=os.environ['REGION'], dynamodb_local_endpoint=os.environ['DYNAMO_ENDPOINT']) except KeyError: repo = DynamoRepository(region_name=os.environ['REGION'], ) supplier_distributors = repo.get_all_distributor_suppliers( distributor_id) distributors = [ item['supplier_distributor_id'] for item in supplier_distributors ] try: entity_id = params['entity_id'] item = context.repo.get_purchase_order_by_id(entity_id, supplier_id, distributors) return {'statusCode': 200, 'body': json.dumps(item)} except NoSuchEntity as ex: return { 'statusCode': 404, 'body': json.dumps({ 'error': '{RESOURCE} Resource not found'.format(RESOURCE=str(ex)) }) }