add skills seeds and implement api

This commit is contained in:
2021-06-07 17:52:14 +02:00
parent 802f227676
commit 5321144dc0
6 changed files with 43 additions and 3 deletions

View File

@ -1,5 +1,34 @@
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