Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend] Fixed cases list and count routes to show info from 'data' folder. #154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ ENV/
.vscode/

# SQLite data
flask-backend/api/db.sqlite3
flask-backend/api/db.sqlite3

data/
48 changes: 42 additions & 6 deletions flask-backend/api/routes/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
amlannandy marked this conversation as resolved.
Show resolved Hide resolved
# 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():
Expand All @@ -41,6 +74,7 @@ def deletecase():
db.session.commit()
return 'case deleted', 202


@case.route('/open/<case_name>', methods=["GET"])
def openCase(case_name):
os.chdir('../../..')
Expand All @@ -49,6 +83,7 @@ def openCase(case_name):
files = os.listdir(path)
return files


@case.route('/list-files/<case_name>/<folder_name>', methods=["GET"])
def openFolder(case_name, folder_name):
os.chdir('../../..')
Expand All @@ -57,9 +92,10 @@ def openFolder(case_name, folder_name):
files = os.listdir(path)
return files


@case.route('/list-files/<case_name>/<folder_name>/<file_name>', 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
return File