Skip to content

Commit

Permalink
Improved not found handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BasMonkey committed May 27, 2024
1 parent 745e0df commit af29f03
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ExonCov/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ def get_summary_by_sample_name_and_run_id_api(sample_name, run_id):
"""
samples = get_samples_by_like_sample_name_or_like_run_id(sample_name, run_id)
samples_list = []
for sample in samples:
samples_list.append(model_to_dict(sample))
if len(samples) > 0:
for sample in samples:
samples_list.append(model_to_dict(sample))
else:
samples_list.append(generate_not_found_dict())
return jsonify(samples_list)


Expand All @@ -125,11 +128,12 @@ def get_sample_by_sample_name_api(sample_name):
Returns:
The sample as a JSON object if it is found in the database
"""
if get_sample_by_id(sample_name):
result = get_sample_by_sample_name(sample_name)
sample = get_sample_by_id(sample_name)
if sample:
result = model_to_dict(sample)
else:
result = generate_not_found_dict()
return jsonify(model_to_dict(result))
return jsonify(result)


@app.route('/api/samples/run/<run_id>')
Expand All @@ -146,6 +150,9 @@ def get_summary_by_run_id_api(run_id):
"""
samples = get_sample_by_like_run_id(run_id)
samples_list = []
for sample in samples:
samples_list.append(model_to_dict(sample))
if len(samples) > 0:
for sample in samples:
samples_list.append(model_to_dict(sample))
else:
samples_list.append(generate_not_found_dict())
return jsonify(samples_list)

0 comments on commit af29f03

Please sign in to comment.