Beispiel #1
0
def log_data(u_id, d_id):
    if g.current_user.id != u_id or Device.query.get(
            d_id).user_id != g.current_user.id:
        abort(403)

    data = request.get_json() or {}

    if 'value' not in data:
        return bad_request('must include a value')

    logging = Data(device=Device.query.get(d_id))
    logging.date = datetime.utcnow()
    logging.from_dict(data)
    db.session.add(logging)
    db.session.commit()
    response = jsonify(logging.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('api.get_device', id=u_id)

    return response
def createDataEntry():
    data = request.get_json() or {}
    print(data)

    if 'device_id' not in data or 'room_temp' not in data or 'room_humd' not in data or 'baby_temp' not in data:
        return bad_request('Corrupted data!')

    #Create data object
    dataEntry = Data()
    dataEntry.from_dict(data)

    print(dataEntry)

    #Update db
    db.session.add(dataEntry)
    db.session.commit()

    #Return the response
    response = jsonify()
    response.status_code = 201
    return response