From 9d4b765d7759b94e135e8675c5cac66f2ed879af Mon Sep 17 00:00:00 2001 From: Amlan Kumar Nandy Date: Wed, 10 Mar 2021 09:51:18 +0530 Subject: [PATCH 1/2] fixed cases list and count routes --- .gitignore | 4 ++- flask-backend/api/routes/case.py | 50 ++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3f6febc1..a0a9bbb5 100644 --- a/.gitignore +++ b/.gitignore @@ -104,4 +104,6 @@ ENV/ .vscode/ # SQLite data -flask-backend/api/db.sqlite3 \ No newline at end of file +flask-backend/api/db.sqlite3 + +data/ \ No newline at end of file diff --git a/flask-backend/api/routes/case.py b/flask-backend/api/routes/case.py index 0141b75e..30c6b0f4 100644 --- a/flask-backend/api/routes/case.py +++ b/flask-backend/api/routes/case.py @@ -12,16 +12,51 @@ case = Blueprint('case', __name__, url_prefix='/case') +dirname = os.path.dirname(__file__) +cases_data_path = os.path.join(dirname, '../../../data/') + + @case.route('/count', methods=["GET"]) def count(): - return jsonify({'status':200, - 'total_users':Case.query.count()}) + try: + os.chdir('../../..') + os.chdir(ROOT_DIR) + cases = os.listdir(cases_data_path) + print(cases_data_path, cases) + except FileNotFoundError as err: + # If data folder is not found, return empty list as no cases have been created + response = { + 'success': True, + 'data': 0, + } + return jsonify(response), 200 + response = { + 'success': True, + 'data': len(cases), + } + return jsonify(response), 200 + @case.route('/list', methods=["GET"]) def list(): - all_cases = Case.query.order_by(Case.timestamp).all() - result = cases_schema.dump(all_cases) - return jsonify(result) + try: + os.chdir('../../..') + os.chdir(ROOT_DIR) + cases = os.listdir(cases_data_path) + print(cases_data_path, cases) + except FileNotFoundError as err: + # If data folder is not found, return empty list as no cases have been created + response = { + 'success': True, + 'data': [], + } + return jsonify(response), 200 + response = { + 'success': True, + 'data': cases, + } + return jsonify(response), 200 + @case.route('/delete', methods=['POST']) def deletecase(): @@ -41,6 +76,7 @@ def deletecase(): db.session.commit() return 'case deleted', 202 + @case.route('/open/', methods=["GET"]) def openCase(case_name): os.chdir('../../..') @@ -49,6 +85,7 @@ def openCase(case_name): files = os.listdir(path) return files + @case.route('/list-files//', methods=["GET"]) def openFolder(case_name, folder_name): os.chdir('../../..') @@ -57,9 +94,10 @@ def openFolder(case_name, folder_name): files = os.listdir(path) return files + @case.route('/list-files///', methods=["GET"]) def openFile(case_name, folder_name, file_name): os.chdir('../../..') File = os.getcwd()+'/data/'+case_name+'/'+folder_name+'/'+file_name os.chdir(ROOT_DIR) - return File \ No newline at end of file + return File From 868c7d8b90cfa77c9f0ed3d3712a76ab95349c1b Mon Sep 17 00:00:00 2001 From: Amlan Date: Wed, 10 Mar 2021 15:18:22 +0530 Subject: [PATCH 2/2] Removed print statements --- flask-backend/api/routes/case.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/flask-backend/api/routes/case.py b/flask-backend/api/routes/case.py index 30c6b0f4..4aa8616f 100644 --- a/flask-backend/api/routes/case.py +++ b/flask-backend/api/routes/case.py @@ -22,7 +22,6 @@ def count(): os.chdir('../../..') os.chdir(ROOT_DIR) cases = os.listdir(cases_data_path) - print(cases_data_path, cases) except FileNotFoundError as err: # If data folder is not found, return empty list as no cases have been created response = { @@ -43,7 +42,6 @@ def list(): os.chdir('../../..') os.chdir(ROOT_DIR) cases = os.listdir(cases_data_path) - print(cases_data_path, cases) except FileNotFoundError as err: # If data folder is not found, return empty list as no cases have been created response = {