Skip to content

Commit

Permalink
search sestava
Browse files Browse the repository at this point in the history
  • Loading branch information
kokes committed Dec 19, 2023
1 parent dba0068 commit b5a0a54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 0 additions & 4 deletions server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
# TODO: presun API z __main__
from server.__main__ import API

__all__ = [API]
18 changes: 16 additions & 2 deletions server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import argparse
import logging

from flask import Flask, jsonify, render_template
from sqlalchemy import create_engine
from flask import Flask, abort, jsonify, render_template, request
from sqlalchemy import create_engine, text


class API(Flask):
Expand All @@ -14,13 +14,27 @@ def __init__(self, import_name, connstring: str):

self.route("/", methods=["GET"])(self.index)
self.route("/status", methods=["GET"])(self.status)
self.route("/api/search", methods=["GET"])(self.search)
# self.route("/api/datasets", methods=["GET"])(self.datasets)

def status(self):
return jsonify({"status": "ok"})

def index(self):
return render_template("index.j2")

def search(self):
q = request.args.get("q")
if not q:
abort(400, "missing query parameter 'q'")

results = []
with self.engine.begin() as conn:
cursor = conn.execute(text("SELECT 1"))
results = [str(j) for j in cursor.fetchall()]

return jsonify({"status": "ok", "results": results})


if __name__ == "__main__":
logging.getLogger().setLevel(logging.INFO)
Expand Down

0 comments on commit b5a0a54

Please sign in to comment.