diff options
Diffstat (limited to 'gn3/api/metadata_api')
-rw-r--r-- | gn3/api/metadata_api/wiki.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/gn3/api/metadata_api/wiki.py b/gn3/api/metadata_api/wiki.py index a4abef6..9ea0d53 100644 --- a/gn3/api/metadata_api/wiki.py +++ b/gn3/api/metadata_api/wiki.py @@ -5,8 +5,9 @@ from typing import Any, Dict from flask import Blueprint, request, jsonify, current_app, make_response from gn3 import db_utils from gn3.db import wiki -from gn3.db.rdf import (query_frame_and_compact, - get_wiki_entries_by_symbol) +from gn3.db.rdf import query_frame_and_compact +from gn3.db.rdf.wiki import (get_wiki_entries_by_symbol, + get_comment_history) wiki_blueprint = Blueprint("wiki", __name__, url_prefix="wiki") @@ -71,7 +72,6 @@ def edit_wiki(comment_id: int): @wiki_blueprint.route("/<string:symbol>", methods=["GET"]) def get_wiki_entries(symbol: str): """Fetch wiki entries""" - content_type = request.headers.get("Content-Type") status_code = 200 response = get_wiki_entries_by_symbol( symbol=symbol, @@ -80,7 +80,7 @@ def get_wiki_entries(symbol: str): if not data: data = {} status_code = 404 - if content_type == "application/ld+json": + if request.headers.get("Accept") == "application/ld+json": payload = make_response(response) payload.headers["Content-Type"] = "application/ld+json" return payload, status_code @@ -117,3 +117,19 @@ def get_species(): species_dict = wiki.get_species(cursor) return jsonify(species_dict) return jsonify(error="Error getting species, most likely due to DB error!"), 500 + + +@wiki_blueprint.route("/<int:comment_id>/history", methods=["GET"]) +def get_history(comment_id): + status_code = 200 + response = get_comment_history(comment_id=comment_id, + sparql_uri=current_app.config["SPARQL_ENDPOINT"]) + data = response.get("data") + if not data: + data = {} + status_code = 404 + if request.headers.get("Accept") == "application/ld+json": + payload = make_response(response) + payload.headers["Content-Type"] = "application/ld+json" + return payload, status_code + return jsonify(data), status_code |