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..4aa8616f 100644 --- a/flask-backend/api/routes/case.py +++ b/flask-backend/api/routes/case.py @@ -12,16 +12,49 @@ 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) + 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) + 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 +74,7 @@ def deletecase(): db.session.commit() return 'case deleted', 202 + @case.route('/open/', methods=["GET"]) def openCase(case_name): os.chdir('../../..') @@ -49,6 +83,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 +92,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