Пример #1
0
def query_by(by):
    """ Endpoint to query items table by given values

        @Params:
            - by: <str> column to compare values with
            - keys: <str> can be item_uuid, gtin, name, description

        @Response:
            - resp: items list
        
        @Example:
            /query/gtin?keys=07501034691224,07501284858385
    """
    logger.info("Query Items by Item UUID...")
    params = request.args.to_dict()
    logger.debug(params)
    # Validate required params
    _needed_params = {'keys'}
    if not _needed_params.issubset(params):
        raise errors.ApiError(70001, "Missing required key params")
    # Complement optional params, and set default if needed
    _opt_params = {'cols': '', 'p':1, 'ipp': 50}
    for _o, _dft  in _opt_params.items():
        if _o not in params:
            params[_o] = _dft
    _items = Item.query(by, **params)
    return jsonify({
        'status': 'OK',
        'items': _items
    })
Пример #2
0
def get_byitem():
    """ Endpoint to fetch items by item_uuids
    """
    logger.info("Query Items by Item UUID...")
    params = request.args.to_dict()
    logger.debug(params)
    # Validate required params
    _needed_params = {'keys'}
    if not _needed_params.issubset(params):
        raise errors.ApiError(70001, "Missing required key params")
    # Complement optional params, and set default if needed
    _opt_params = {'cols': '', 'p':1, 'ipp': 50}
    for _o, _dft  in _opt_params.items():
        if _o not in params:
            params[_o] = _dft
    _items = Item.query('item_uuid', **params)
    return jsonify({
        'status': 'OK',
        'items': _items
        })