Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added api/analytics.py
Empty file.
53 changes: 53 additions & 0 deletions api/backend/CustomerReview/customer-review_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from flask import Blueprint
from flask import request
from flask import jsonify
from flask import make_response
from flask import current_app
from backend.db_connection import db

#------------------------------------------------------------
# Create a new Blueprint object, which is a collection of
# routes.
customers = Blueprint('CustomerReviews', __name__)


#------------------------------------------------------------
# Retrieve all customer reviews for a laundromat
@customers.route('/CustomerReviews/<laundromat_id>', methods=['GET'])
def get_customer_reviews(laundromat_id):
cursor = db.get_db().cursor()
query = '''
SELECT review_id, laundromat_id, user_id, rating, text, title
FROM CustomerReviews
WHERE laundromat_id = %s
'''
cursor.execute(query, (laundromat_id,))
reviews = cursor.fetchall()
the_response = make_response(jsonify(reviews))
the_response.status_code = 200
return the_response

#------------------------------------------------------------
# Make a user review for a laundromat
@customers.route('/CustomerReviews/<review_id>', methods=['POST'])
def create_review(review_id):
data = request.json()
current_app.logger.info(data)


laundromat_id = data.get('laundromat_id')
review_id = data.get('review_id')
user_id = data.get('user_id')
rating = data.get('rating')
text = data.get('text')
title = data.get('title')

cursor = db.get_db().cursor()
new_rev_query = f'''
INSERT INTO customer_reviews (review_id, laundromat_id, user_id, rating, comment, date)
VALUES ('{review_id}', '{laundromat_id}', '{user_id}', '{rating}', '{text}', {title}')
'''
cursor.execute(new_rev_query, (review_id, laundromat_id, user_id, rating, text, title))
db.get_db().commit()

return make_response(jsonify({'message': 'Review created successfully'}), 201)
88 changes: 88 additions & 0 deletions api/customers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from flask import Blueprint, jsonify, request


# 创建 Blueprint 实例
customers_blueprint = Blueprint('customers', __name__)

# 建立数据库连接(connect to MySQL server)
def db_connection():
return mysql.connector.connect(
# name in docker
host='',
user='',
password='',
database=''
)

# GET /customers 获取所有用户
@customers_blueprint.route('/customers', methods = ['GET'])
def get_all_customers():
connection = db_connection()
cursor = connection.cursor(dictionary = True)
cursor.execute("SELECT * FROM Customers")
results = cursor.fetchall()

cursor.close()
connection.close()
return jsonify(results)

# GET /customers/search?name=xxx&email=xxx 搜索用户
@customers_blueprint.route('/customers/search', methods = ['GET'])
def search_customers():
name = request.args.get('name')
email = request.args.get('email')
connection = get_db_connection()
cursor = connection.cursor(dictionary = True)
SQLuery = "SELECT * FROM Customers WHERE firstname LIKE %s OR email LIKE %s"
cursor.execute(SQLuery, (f"%{name}%", f"%{email}%"))
results = cursor.fetchall()

cursor.close()
connection.close()
return jsonify(results)




############## 从这里开始





# POST /customers 添加新用户
@customers_blueprint.route('/customers', methods = ['POST'])
def add_customer():
data = request.get_json()
connection = get_db_connection()
cursor = connection.cursor()
SQLquery = "INSERT INTO Customers (firstname, lastname, email, address) VALUES (%s, %s, %s, %s)"
cursor.execute(SQLquery, (data['firstname'], data['lastname'], data['email'], data['address']))
connection.commit()
cursor.close()
connection.close()
return jsonify({'message': 'Customer added successfully'}), 201

# DELETE /customers/<id> → 删除用户
@customers_bp.route('/customers/<int:user_id>', methods=['DELETE'])
def delete_customer(user_id):
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("DELETE FROM Customers WHERE user_id = %s", (user_id,))
conn.commit()
cursor.close()
conn.close()
return jsonify({'message': f'Customer {user_id} deleted'}), 200

# PUT /customers/<id> → 更新用户信息(自定义字段)
@customers_bp.route('/customers/<int:user_id>', methods=['PUT'])
def update_customer(user_id):
data = request.get_json()
conn = get_db_connection()
cursor = conn.cursor()
query = "UPDATE Customers SET firstname=%s, lastname=%s, email=%s, address=%s WHERE user_id=%s"
cursor.execute(query, (data['firstname'], data['lastname'], data['email'], data['address'], user_id))
conn.commit()
cursor.close()
conn.close()
return jsonify({'message': f'Customer {user_id} updated'}), 200
Empty file added api/logs.py
Empty file.
Empty file added api/orders.py
Empty file.
Binary file added app/src/assets/suds_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/modules/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def SideBarLinks(show_home=False):
"""

# add a logo to the sidebar always
st.sidebar.image("assets/logo.png", width=150)
st.sidebar.image("assets/suds_logo.png", width=150)

# If there is no logged in user, redirect to the Home (Landing) page
if "authenticated" not in st.session_state:
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/02_Map_Demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SideBarLinks()

# add the logo
add_logo("assets/logo.png", height=400)
add_logo("assets/suds_logo.png", height=400)

# set up the page
st.markdown("# Mapping Demo")
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/03_Simple_Chat_Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def response_generator():
#-----------------------------------------------------------------------

st.set_page_config (page_title="Sample Chat Bot", page_icon="🤖")
add_logo("assets/logo.png", height=400)
add_logo("assets/suds_logo.png", height=400)

st.title("Echo Bot 🤖")

Expand Down
7 changes: 6 additions & 1 deletion app/src/pages/20_Admin_Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

st.title('System Admin Home Page')

if st.button('Update ML Models',
if st.button('Add New User',
type='primary',
use_container_width=True):
st.switch_page('pages/21_ML_Model_Mgmt.py')

if st.button('Remove User',
type='primary',
use_container_width=True):
st.switch_page('pages/21_ML_Model_Mgmt.py')
Loading