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
12 changes: 12 additions & 0 deletions .idea/3200_Project_Sarkar.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ WORKDIR /apicode

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install mysql-connector-python

COPY . .

EXPOSE 4000

CMD [ "python", "backend_app.py"]


53 changes: 53 additions & 0 deletions api/backend/CustomerReviews/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)
36 changes: 36 additions & 0 deletions api/backend/analytics/analytics_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask import Blueprint, jsonify, make_response, current_app
from backend.db_connection import db_connection

analytics_blueprint = Blueprint('analytics', __name__)

@analytics_blueprint.route('/analytics', methods = ['GET'])
def get_analytics():
connection = db_connection()
cursor = connection.cursor(dictionary = True)
cursor.execute("SELECT * FROM AppAnalytics")
results = cursor.fetchall()

cursor.close()
connection.close()
return make_response(jsonify(results), 200)


'''

from flask import Blueprint, jsonify
from db import db_connection

# blueprint instance
analytics_blueprint = Blueprint('analytics', __name__)

@analytics_blueprint.route('/analytics', methods = ['GET'])
def get_analytics():
connection = db_connection()
cursor = connection.cursor(dictionary = True)
cursor.execute("SELECT * FROM AppAnalytics")
results = cursor.fetchall()

cursor.close()
connection.close()
return jsonify(results)
'''
83 changes: 0 additions & 83 deletions api/backend/customers/customer_routes.py

This file was deleted.

13 changes: 12 additions & 1 deletion api/backend/db_connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@

# the parameter instructs the connection to return data
# as a dictionary object.
db = MySQL(cursorclass=cursors.DictCursor)
# as a dictionary object.
db = MySQL(cursorclass=cursors.DictCursor)

import mysql.connector

def db_connection():
return mysql.connector.connect(
host='db',
user='root',
password='password123',
database='projectdb'
)
30 changes: 30 additions & 0 deletions api/backend/laundromat/laundromat_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from flask import Blueprint, request, jsonify
from backend.db_connection import db

laundromat = Blueprint('laundromat', __name__)

@laundromat.route('/laundromat', methods=['GET'])
def get_sorted_laundromats():
attribute = request.args.get('attribute', 'pricing')
sort_order = request.args.get('sort', 'asc')
limit = int(request.args.get('limit', 1))

if attribute not in ['pricing', 'avgtime']:
return jsonify({'error': 'Invalid attribute'}), 400

sort_order = sort_order.lower()
if sort_order not in ['asc', 'desc']:
return jsonify({'error': 'Invalid sort order'}), 400

conn = db.connect()
cursor = conn.cursor()

try:
query = f"SELECT * FROM laundromats ORDER BY {attribute} {sort_order.upper()} LIMIT %s"
cursor.execute(query, (limit,))
results = cursor.fetchall()
return jsonify(results)
finally:
cursor.close()
conn.close()

15 changes: 15 additions & 0 deletions api/backend/logs/logs_routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import Blueprint, jsonify
from backend.db_connection import db_connection

logs_blueprint = Blueprint('logs', __name__)

@logs_blueprint.route('/logs', methods = ['GET'])
def get_logs():
connection = db_connection()
cursor = connection.cursor(dictionary = True)
cursor.execute("SELECT * FROM Logs")
results = cursor.fetchall()

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