diff options
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/api/metadata_api/wiki.py | 16 | ||||
-rw-r--r-- | gn3/db/wiki.py | 7 |
2 files changed, 15 insertions, 8 deletions
diff --git a/gn3/api/metadata_api/wiki.py b/gn3/api/metadata_api/wiki.py index 7e22c94..dc131d3 100644 --- a/gn3/api/metadata_api/wiki.py +++ b/gn3/api/metadata_api/wiki.py @@ -1,5 +1,7 @@ +"""API for accessing/editting wiki metadata""" + import datetime -from typing import Any, Dict, List +from typing import Any, Dict from flask import Blueprint, request, jsonify, current_app from gn3 import db_utils from gn3.db import wiki @@ -8,12 +10,9 @@ from gn3.db import wiki wiki_blueprint = Blueprint("wiki", __name__, url_prefix="wiki") -class MissingDBDataException(Exception): - pass - - @wiki_blueprint.route("/<int:comment_id>/edit", methods=["POST"]) def edit_wiki(comment_id: int): + """Edit wiki comment. This is achieved by adding another entry with a new VersionId""" # FIXME: attempt to check and fix for types here with relevant errors payload: Dict[str, Any] = request.json pubmed_ids = [str(x) for x in payload.get("pubmed_ids", [])] @@ -44,13 +43,16 @@ def edit_wiki(comment_id: int): category_ids = wiki.get_categories_ids(cursor, payload["categories"]) species_id = wiki.get_species_id(cursor, payload["species"]) next_version = wiki.get_next_comment_version(cursor, comment_id) - except MissingDBDataException as missing_exc: + except wiki.MissingDBDataException as missing_exc: return jsonify(error=f"Error editting wiki entry, {missing_exc}"), 500 insert_dict["SpeciesID"] = species_id insert_dict["versionId"] = next_version current_app.logger.debug(f"Running query: {insert_query}") cursor.execute(insert_query, insert_dict) - category_addition_query = "INSERT INTO GeneRIFXRef (GeneRIFId, versionId, GeneCategoryId) VALUES (%s, %s, %s)" + category_addition_query = """ + INSERT INTO GeneRIFXRef (GeneRIFId, versionId, GeneCategoryId) + VALUES (%s, %s, %s) + """ for cat_id in category_ids: current_app.logger.debug(f"Running query: {category_addition_query}") diff --git a/gn3/db/wiki.py b/gn3/db/wiki.py index a56f26c..c3cfee0 100644 --- a/gn3/db/wiki.py +++ b/gn3/db/wiki.py @@ -1,11 +1,14 @@ +"""Helper functions to access wiki entries""" + from typing import List class MissingDBDataException(Exception): - pass + """Error due to DB missing some data""" def get_species_id(cursor, species_name: str) -> int: + """Find species id given species `Name`""" cursor.execute("SELECT SpeciesID from Species WHERE Name = %s", (species_name,)) species_ids = cursor.fetchall() if len(species_ids) != 1: @@ -16,6 +19,7 @@ def get_species_id(cursor, species_name: str) -> int: def get_next_comment_version(cursor, comment_id: int) -> int: + """Find the version to add, usually latest_version + 1""" cursor.execute( "SELECT MAX(versionId) as version_id from GeneRIF WHERE Id = %s", (comment_id,) ) @@ -26,6 +30,7 @@ def get_next_comment_version(cursor, comment_id: int) -> int: def get_categories_ids(cursor, categories: List[str]) -> List[int]: + """Get the categories_ids from a list of category strings""" cursor.execute("SELECT Name, Id from GeneCategory") raw_categories = cursor.fetchall() dict_cats = dict(raw_categories) |