# bultin library

# external libraries
from sanic import Sanic
from sanic.response import text, json
from condor.dbutil import requires_db
from condor.models import Bibliography, RankingMatrix, TermDocumentMatrix, Document


app = Sanic(__name__)


@app.route("/ping")
async def start(request):
    return text("pong")


@app.route("/ranking", methods=["GET"])
@requires_db
async def list_rankings(db, request):
    ranking_matrices = [
        {
            "eid": matrix.eid,
            "kind": matrix.kind,
            "build_options": matrix.build_options,
            "ranking_matrix_path": matrix.ranking_matrix_path
        }
        for matrix in RankingMatrix.list(db)
    ]
    return json(ranking_matrices)


@app.route("/bibliography")
@requires_db
async def list_bibliographies(db, request):
    to_return = [{
        "eid": bib.eid,
        "description": bib.description,
        "created": bib.created,
        "modified": bib.modified
    } for bib in Bibliography.list(db)]
    return json(to_return)


@app.route('/document')
@requires_db
async def list_documents(database, request):
    """
    List the documents associated with a bibliography.
    """
    bibliography_eid = request.args.get('bibliography', None)
    if not bibliography_eid:
        return json({
            'error': 'You must suply a bibliography eid.',
            'details': 'Fill in the bibliography field.'
        }, status=400)
    to_return = [
        {
            'eid': doc.eid,
            'title': doc.title,
            'description': doc.description,
            'created': doc.created,
            'modified': doc.modified
        }
        for doc in Document.list(database, bibliography_eid)
    ]
    return json(to_return)


@app.route('/document/<eid>')
@requires_db
async def document(database, request, eid):
    doc = Document.find_by_eid(database, eid)
    if not doc:
        return json({
            'message': 'The especified eid is not found on database.',
        }, status=404)
    return json(doc)



@app.route("/matrix")
@requires_db
async def list_term_document_matrices(db, request):
    to_return = [{
        "eid": document.eid,
        "bibliography_eid": document.bibliography_eid,
        "bibliography_options": document.bibliography_options,
        "processing_options": document.processing_options,
        "term_list_path": document.term_list_path,
        "matrix_path": document.matrix_path
    } for document in TermDocumentMatrix.list(db)]
    return json(to_return)


if __name__ == "__main__":
    app.run(
        debug=True,
        host="0.0.0.0",
        port=8000,
        log_config=None,
    )

@@ -2013,19 +2013,180 @@
 rn json(
-doc
+%7B%0A        'eid': doc.eid,%0A        'title': doc.title,%0A        'description': doc.description,%0A        'created': doc.created,%0A        'modified': doc.modified%0A    %7D
 )%0A%0A%0A%0A@ap

Resolve method for a single document