Merge branch 'main' of gitlab.fdmci.hva.nl:propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59

This commit is contained in:
Bram Barbieri
2024-03-20 11:16:34 +01:00
3 changed files with 58 additions and 10 deletions

View File

@@ -2,7 +2,7 @@
-- Wed Mar 13 16:04:58 2024
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
-- CHANGE NODEID TO AUTO INCREMENET IN NODE TABLE
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

View File

@@ -1,4 +1,4 @@
from flask import Flask, request
from flask import Flask, request, jsonify
import mysql.connector
from queries import *
app = Flask(__name__)
@@ -10,27 +10,68 @@ def index():
MAC = request.args.get('MAC', default = None)
return getData(node, dataType, MAC)
def getData(node, dataType, MAC):
try:
@app.route('/putData', methods=['PUT'])
def putData():
node_id = request.json.get('node_id', None)
new_name = request.json.get('new_name', None)
new_location = request.json.get('new_location', None)
if node_id is None:
return jsonify({"error": "node_id is required"}), 400
mydb = mysql.connector.connect(
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()
query = get_query(node, name, location, MAC)
cursor = mydb.cursor(dictionary=True) # Enable dictionary output
cursor.execute(query)
result = cursor.fetchall() # Fetch the results
cursor.close()
mydb.close()
return result
def loginDB():
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="Dingleberries69!",
database="NodeData"
)
return mydb
def getData(node, dataType, MAC):
mydb = loginDB()
query = get_query(node, dataType, MAC)
cursor = mydb.cursor(dictionary=True) # Enable dictionary output
cursor.execute(query)
result = cursor.fetchall() # Fetch the results
cursor.close()
mydb.close()
return result
except mysql.connector.Error as err:
print("MySQL Error:", err)
return "MySQL Error: " + str(err)
if __name__ == '__main__':
app.run(debug=True, host='localhost')
app.run(debug=True, host='localhost')

View File

@@ -53,4 +53,11 @@ and im going to continue with working on the connection between the websocket an
15 - 3- 2024 {
We are all making preperations for the sprint-review.
}
}
3/19/2024
Dano, oop arduino
Bram, nodes registereen als er een nieuwe binnenkomt
Sietse, onderdelen bestellen, verder user story 46: nodes beheren op website.
Sam, tft scherm, rest api ombouwen om data in node tabel te douwen