ki-backend/ki/routes.py

35 lines
677 B
Python

from flask import request
from ki.models import Skill
from app import app
def models_to_list(models):
models_list = []
for model in models:
models_list.append(model.to_dict())
return models_list
@app.route("/")
def hello_world():
return "KI"
@app.route("/skills")
def get_skills():
skills_query = Skill.query
if "search" in request.args:
skills_query = skills_query.filter(Skill.name.startswith(request.args.get("search")))
skills = skills_query.order_by(Skill.name) \
.limit(10) \
.all()
api_skills = models_to_list(skills)
response_data = {"skills": api_skills}
return response_data