Example #1
0
def insert(table):
    table = "{0}_{1}".format(table, "dev")
    dynamoDB = DynamoDB(table)

    if request.is_json:
        data = request.get_json()
        print(data)
        if ('valueHospital' in data or 'valueRepresentante' in data):
            data['valueHospital'] = decimal.Decimal(str(data['valueHospital']))
            data['valueRepresentante'] = decimal.Decimal(
                str(data['valueRepresentante']))
            data['quant'] = decimal.Decimal(str(data['quant']))

        elif ('maoObraValue' in data or 'valorVisita' in data):
            data['maoObraValue'] = decimal.Decimal(str(data['maoObraValue']))
            data['valorVisita'] = decimal.Decimal(str(data['valorVisita']))

            if (data['replacedParts'] != None):
                for replacedParts in data['replacedParts']:
                    replacedParts['value'] = decimal.Decimal(
                        str(replacedParts['value']))
                    replacedParts['quant'] = decimal.Decimal(
                        str(replacedParts['quant']))

        response = dynamoDB.insert(data)
        return jsonify(response)
    else:
        return jsonify({
            'message': 'Request was not JSON',
            'response': None
        }), 500
Example #2
0
def scan(table):
    table = "{0}_{1}".format(table, "dev")
    dynamo = DynamoDB(table)

    response = dynamo.scan()
    print(response)
    return json.dumps(response, default=decimal_default)
Example #3
0
def login(table):
    table = "{0}_{1}".format(table, "dev")
    dynamo = DynamoDB(table)

    print('###### Request: ######', request.get_json())

    if request.is_json:
        data = request.get_json()

        id = data['id']

        user = {'id': id}

        password = data['password']

        response = dynamo.select(user)

        # print("response app_dev.py", response)
        # print("response app_dev.py", response[0])

        if 'id' in response[0]['response'] and response[0]['response'][
                'id'] == id and response[0]['response']['password'] == password:
            return jsonify(response)

        return jsonify({'id': None, 'password': None})
    else:
        return jsonify({
            'message': 'Request was not JSON',
            'response': {}
        }), 500
Example #4
0
def delete(table):
    dynamoDB = DynamoDB(table)

    if request.is_json:
        data = request.get_json()
        print(data)
        response = dynamoDB.delete(data)
        return jsonify(response)
    else:
        return jsonify({
            'message': 'Request was not JSON',
            'response': None
        }), 500
Example #5
0
def query(table):
    dynamo = DynamoDB(table)
    query_parameters = request.args

    chave = query_parameters['key']
    valor = query_parameters['value']
    print('key={0} & valor={1}'.format(chave, valor))

    if chave == '' or valor == '':
        return jsonify(bad_request(400))

    response = dynamo.query(chave, valor)
    print(response)
    return jsonify(response)
Example #6
0
def select(table):
    dynamo = DynamoDB(table)

    print('###### Request: ######', request.get_json())

    if request.is_json:
        data = request.get_json()
        print(data)
        response = dynamo.select(data)

        return json.dumps(response, default=decimal_default)
    else:
        return jsonify({
            'message': 'Request was not JSON',
            'response': None
        }), 500
Example #7
0
def update(table):
    dynamoDB = DynamoDB(table)

    if request.is_json:
        data = request.get_json()
        print(data)
        if ('valueHospital' in data or 'valueRepresentante' in data):
            data['valueHospital'] = decimal.Decimal(str(data['valueHospital']))
            data['valueRepresentante'] = decimal.Decimal(
                str(data['valueRepresentante']))
            data['quant'] = decimal.Decimal(str(data['quant']))
        response = dynamoDB.update(data)
        return jsonify(response)
    else:
        return jsonify({
            'message': 'Request was not JSON',
            'response': None
        }), 500
Example #8
0
def scan(table):
    dynamo = DynamoDB(table)

    response = dynamo.scan()
    print(response)
    return json.dumps(response, default=decimal_default)