-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.py
30 lines (26 loc) · 1.01 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import request
from my_project_template.model.allele import InvalidAllele
from my_project_template.my_project_template import match
def slug_match_controller():
if request.json:
# Check the request
try:
patient_slug_glstring = request.json["patient_slug"]
donor_slug_glstring = request.json["donor_slug"]
except KeyError:
return {"message": "Invalid data in patient_slug/donor_slug"}, 400
# Perform match
try:
donor_slug, matched, patient_slug = match(
patient_slug_glstring, donor_slug_glstring
)
matched_result = "Match" if matched else "No Match"
return {
"matched": matched_result,
"patient_slug": str(patient_slug),
"donor_slug": str(donor_slug),
}, 200
except InvalidAllele as e:
return {"message": e.message}, 400
# if no data is sent
return {"message": "No input provided"}, 404