Added so you can change node information
This commit is contained in:
@@ -10,42 +10,20 @@ def index():
|
|||||||
MAC = request.args.get('MAC', default = None)
|
MAC = request.args.get('MAC', default = None)
|
||||||
return getData(node, dataType, MAC)
|
return getData(node, dataType, MAC)
|
||||||
|
|
||||||
@app.route('/putData', methods=['PUT'])
|
@app.route('/updateData')
|
||||||
def putData():
|
def updateDataIndex():
|
||||||
node_id = request.json.get('node_id', None)
|
node_id = request.args.get('node', None)
|
||||||
new_name = request.json.get('new_name', None)
|
new_name = request.args.get('name', None)
|
||||||
new_location = request.json.get('new_location', None)
|
new_location = request.args.get('location', None)
|
||||||
|
return updateData(node_id, new_name, new_location)
|
||||||
|
|
||||||
if node_id is None:
|
|
||||||
return jsonify({"error": "node_id is required"}), 400
|
|
||||||
|
|
||||||
mydb = mysql.connector.connect(
|
def updateData(node, name, location):
|
||||||
host="localhost",
|
|
||||||
user="root",
|
|
||||||
password="Dingleberries69!",
|
|
||||||
database="NodeData"
|
|
||||||
)
|
|
||||||
|
|
||||||
cursor = mydb.cursor()
|
|
||||||
|
|
||||||
if new_name is not None:
|
|
||||||
cursor.execute("UPDATE Node SET Name = %s WHERE NodeID = %s", (new_name, node_id))
|
|
||||||
mydb.commit()
|
|
||||||
|
|
||||||
if new_location is not None:
|
|
||||||
cursor.execute("UPDATE Node SET Location = %s WHERE NodeID = %s", (new_location, node_id))
|
|
||||||
mydb.commit()
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
mydb.close()
|
|
||||||
|
|
||||||
return jsonify({"message": "Node updated successfully"}), 200
|
|
||||||
|
|
||||||
def putData(node, name, location, MAC):
|
|
||||||
mydb = loginDB()
|
mydb = loginDB()
|
||||||
query = get_query(node, name, location, MAC)
|
query = update_query(node, name, location)
|
||||||
cursor = mydb.cursor(dictionary=True) # Enable dictionary output
|
cursor = mydb.cursor(dictionary=True) # Enable dictionary output
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
mydb.commit()
|
||||||
result = cursor.fetchall() # Fetch the results
|
result = cursor.fetchall() # Fetch the results
|
||||||
cursor.close()
|
cursor.close()
|
||||||
mydb.close()
|
mydb.close()
|
||||||
|
@@ -10,3 +10,14 @@ def get_query(node, dataType, MAC):
|
|||||||
else:
|
else:
|
||||||
query = "SELECT * FROM `Measurement`"
|
query = "SELECT * FROM `Measurement`"
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def update_query(node, name, location):
|
||||||
|
if node and name and location:
|
||||||
|
query = f"""
|
||||||
|
UPDATE Node
|
||||||
|
SET Name = '{name}', Location = '{location}'
|
||||||
|
WHERE NodeID = {node};
|
||||||
|
"""
|
||||||
|
return query
|
Reference in New Issue
Block a user