From 61ff5379b615c1684a1fbf32bdf0155f407774ba Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 16:13:49 -0600 Subject: [PATCH 1/8] Implement CRUD operations for employeesV2 Added CRUD operations for employee management including insert, update, delete, and fetch all employees. --- app.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index c0f3d87d8a..95e3dfcbbc 100644 --- a/app.py +++ b/app.py @@ -1,14 +1,65 @@ -from flask import Flask -import os +from flask import Flask, request, jsonify +import mysql.connector app = Flask(__name__) -@app.route('/') -def hello(): - return "Hello World!" +def get_db(): + return mysql.connector.connect( + host="localhost", + user="your_user", + password="your_password", + database="your_database" + ) -if __name__ == '__main__': - port = os.environ.get('FLASK_PORT') or 8080 - port = int(port) +# INSERT +@app.route("/insert", methods=["POST"]) +def insert_row(): + data = request.json + name = data.get("name") + role = data.get("role") - app.run(port=port,host='0.0.0.0') \ No newline at end of file + conn = get_db() + cursor = conn.cursor() + cursor.execute("INSERT INTO employees (name, role) VALUES (%s, %s)", (name, role)) + conn.commit() + + return jsonify({"message": "Row inserted", "id": cursor.lastrowid}) + +# UPDATE +@app.route("/update/", methods=["PUT"]) +def update_row(emp_id): + data = request.json + name = data.get("name") + role = data.get("role") + + conn = get_db() + cursor = conn.cursor() + cursor.execute( + "UPDATE employees SET name=%s, role=%s WHERE id=%s", + (name, role, emp_id) + ) + conn.commit() + + return jsonify({"message": "Row updated"}) + +# DELETE +@app.route("/delete/", methods=["DELETE"]) +def delete_row(emp_id): + conn = get_db() + cursor = conn.cursor() + cursor.execute("DELETE FROM employees WHERE id=%s", (emp_id,)) + conn.commit() + + return jsonify({"message": "Row deleted"}) + +# OPTIONAL: fetch all rows +@app.route("/employees", methods=["GET"]) +def get_all(): + conn = get_db() + cursor = conn.cursor(dictionary=True) + cursor.execute("SELECT * FROM employees") + rows = cursor.fetchall() + return jsonify(rows) + +if __name__ == "__main__": + app.run(debug=True) From 60e4e34273fcb22dca7ca2793c38692aa78aaedb Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 16:20:22 -0600 Subject: [PATCH 2/8] Change MySQL connection credentials Updated database connection parameters for MySQL. --- app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 95e3dfcbbc..9b2f6aa0b7 100644 --- a/app.py +++ b/app.py @@ -6,9 +6,9 @@ def get_db(): return mysql.connector.connect( host="localhost", - user="your_user", - password="your_password", - database="your_database" + user="f832139", + password="password", + database="sampledb" ) # INSERT From 4f1d15195bc32dbe669080fa6ed2db4b1e7dca79 Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 16:38:47 -0600 Subject: [PATCH 3/8] Simplify app by removing database functionality Removed database connection and CRUD operations. Added a simple hello route. --- app.py | 69 ++++++++-------------------------------------------------- 1 file changed, 9 insertions(+), 60 deletions(-) diff --git a/app.py b/app.py index 9b2f6aa0b7..52ea4226ea 100644 --- a/app.py +++ b/app.py @@ -1,65 +1,14 @@ -from flask import Flask, request, jsonify -import mysql.connector +from flask import Flask +import os app = Flask(__name__) -def get_db(): - return mysql.connector.connect( - host="localhost", - user="f832139", - password="password", - database="sampledb" - ) +@app.route('/') +def hello(): + return "Hello World!" -# INSERT -@app.route("/insert", methods=["POST"]) -def insert_row(): - data = request.json - name = data.get("name") - role = data.get("role") +if __name__ == '__main__': + port = os.environ.get('FLASK_PORT') or 8080 + port = int(port) - conn = get_db() - cursor = conn.cursor() - cursor.execute("INSERT INTO employees (name, role) VALUES (%s, %s)", (name, role)) - conn.commit() - - return jsonify({"message": "Row inserted", "id": cursor.lastrowid}) - -# UPDATE -@app.route("/update/", methods=["PUT"]) -def update_row(emp_id): - data = request.json - name = data.get("name") - role = data.get("role") - - conn = get_db() - cursor = conn.cursor() - cursor.execute( - "UPDATE employees SET name=%s, role=%s WHERE id=%s", - (name, role, emp_id) - ) - conn.commit() - - return jsonify({"message": "Row updated"}) - -# DELETE -@app.route("/delete/", methods=["DELETE"]) -def delete_row(emp_id): - conn = get_db() - cursor = conn.cursor() - cursor.execute("DELETE FROM employees WHERE id=%s", (emp_id,)) - conn.commit() - - return jsonify({"message": "Row deleted"}) - -# OPTIONAL: fetch all rows -@app.route("/employees", methods=["GET"]) -def get_all(): - conn = get_db() - cursor = conn.cursor(dictionary=True) - cursor.execute("SELECT * FROM employees") - rows = cursor.fetchall() - return jsonify(rows) - -if __name__ == "__main__": - app.run(debug=True) + app.run(port=port,host='0.0.0.0') From 1f8e7f61c202808c0ee13b755d37d91f70980c0b Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 16:45:48 -0600 Subject: [PATCH 4/8] Implement CRUD operations for employees Added CRUD operations for employee records including insert, update, delete, and fetch all. --- app.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 52ea4226ea..95e3dfcbbc 100644 --- a/app.py +++ b/app.py @@ -1,14 +1,65 @@ -from flask import Flask -import os +from flask import Flask, request, jsonify +import mysql.connector app = Flask(__name__) -@app.route('/') -def hello(): - return "Hello World!" +def get_db(): + return mysql.connector.connect( + host="localhost", + user="your_user", + password="your_password", + database="your_database" + ) -if __name__ == '__main__': - port = os.environ.get('FLASK_PORT') or 8080 - port = int(port) +# INSERT +@app.route("/insert", methods=["POST"]) +def insert_row(): + data = request.json + name = data.get("name") + role = data.get("role") - app.run(port=port,host='0.0.0.0') + conn = get_db() + cursor = conn.cursor() + cursor.execute("INSERT INTO employees (name, role) VALUES (%s, %s)", (name, role)) + conn.commit() + + return jsonify({"message": "Row inserted", "id": cursor.lastrowid}) + +# UPDATE +@app.route("/update/", methods=["PUT"]) +def update_row(emp_id): + data = request.json + name = data.get("name") + role = data.get("role") + + conn = get_db() + cursor = conn.cursor() + cursor.execute( + "UPDATE employees SET name=%s, role=%s WHERE id=%s", + (name, role, emp_id) + ) + conn.commit() + + return jsonify({"message": "Row updated"}) + +# DELETE +@app.route("/delete/", methods=["DELETE"]) +def delete_row(emp_id): + conn = get_db() + cursor = conn.cursor() + cursor.execute("DELETE FROM employees WHERE id=%s", (emp_id,)) + conn.commit() + + return jsonify({"message": "Row deleted"}) + +# OPTIONAL: fetch all rows +@app.route("/employees", methods=["GET"]) +def get_all(): + conn = get_db() + cursor = conn.cursor(dictionary=True) + cursor.execute("SELECT * FROM employees") + rows = cursor.fetchall() + return jsonify(rows) + +if __name__ == "__main__": + app.run(debug=True) From 12c4b469e24caecc1146678fc89f3ae05f7b2e0e Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:54:20 -0600 Subject: [PATCH 5/8] Add mysql-connector-python to requirements --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 51c32f3429..f11d3ae29a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -Flask==3.1.2 \ No newline at end of file +Flask==3.1.2 +mysql-connector-python From 19fcd4903b148446ae1f8082f71bad42c716923b Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 23:25:58 -0600 Subject: [PATCH 6/8] Change Flask app to run on host 0.0.0.0 and port 8081 --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 95e3dfcbbc..e1d6b61e8a 100644 --- a/app.py +++ b/app.py @@ -62,4 +62,4 @@ def get_all(): return jsonify(rows) if __name__ == "__main__": - app.run(debug=True) + app.run(host="0.0.0.0", port=8081, debug=True) From 7451c3dcc3770c8c6deda652ec20db507afb8c03 Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 23:30:46 -0600 Subject: [PATCH 7/8] Change database connection details in get_db function Updated database connection parameters to use specific credentials and database. --- app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index e1d6b61e8a..8e9dfda77e 100644 --- a/app.py +++ b/app.py @@ -6,9 +6,9 @@ def get_db(): return mysql.connector.connect( host="localhost", - user="your_user", - password="your_password", - database="your_database" + user="f832139", + password="password", + database="sampledb" ) # INSERT From ebdbff7545479e1b4154f255f802c05453033f11 Mon Sep 17 00:00:00 2001 From: Pedro777-dev <68801840+Pedro777-dev@users.noreply.github.com> Date: Sat, 17 Jan 2026 23:40:39 -0600 Subject: [PATCH 8/8] Change database host from 'localhost' to 'mysql' --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 8e9dfda77e..e51cc75ce2 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,7 @@ def get_db(): return mysql.connector.connect( - host="localhost", + host="mysql", user="f832139", password="password", database="sampledb"