aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-28 10:51:29 +0300
committerFrederick Muriuki Muriithi2023-10-10 11:12:46 +0300
commitb986218172d8dedbf027bdb65c573e54597674d8 (patch)
treedd4a6bef68a0a7f6294c5e0adeb9fd87a909e80a
parentd8f22144360b22a0ea0f6d81e366150865bbe5fb (diff)
downloadgenenetwork3-b986218172d8dedbf027bdb65c573e54597674d8.tar.gz
Extract fetching of case-attribute names
Extract the fetching of case-attribute names into a separate function that can be used elsewhere.
-rw-r--r--gn3/case_attributes.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/gn3/case_attributes.py b/gn3/case_attributes.py
index 67bb407..78fc579 100644
--- a/gn3/case_attributes.py
+++ b/gn3/case_attributes.py
@@ -13,15 +13,20 @@ from gn3.auth.authorisation.errors import AuthorisationError
caseattr = Blueprint("case-attribute", __name__)
-@caseattr.route("/<int:inbredset_id>/names", methods=["GET"])
-def inbredset_case_attribute_names(inbredset_id: int) -> Response:
- """Retrieve ALL case-attributes for a specific InbredSet group."""
- with (database_connection(current_app.config["SQL_URI"]) as conn,
- conn.cursor(cursorclass=DictCursor) as cursor):
+def __case_attribute_labels_by_inbred_set__(conn, inbredset_id):
+ """Return the case-attribute labels/names for the given InbredSet group."""
+ with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute(
"SELECT * FROM CaseAttribute WHERE InbredSetId=%(inbredset_id)s",
{"inbredset_id": inbredset_id})
- return jsonify(tuple(dict(row) for row in cursor.fetchall()))
+ return tuple(dict(row) for row in cursor.fetchall())
+
+@caseattr.route("/<int:inbredset_id>/names", methods=["GET"])
+def inbredset_case_attribute_names(inbredset_id: int) -> Response:
+ """Retrieve ALL case-attributes for a specific InbredSet group."""
+ with database_connection(current_app.config["SQL_URI"]) as conn:
+ return jsonify(
+ __case_attribute_labels_by_inbred_set__(conn, inbredset_id))
def __by_strain__(accumulator, item):
attr = {item["CaseAttributeName"]: item["CaseAttributeValue"]}