ki-backend/ki/routes.py

35 lines
677 B
Python
Raw Normal View History

2021-06-07 17:52:14 +02:00
from flask import request
from ki.models import Skill
2021-06-06 22:25:10 +02:00
from app import app
2021-06-07 17:52:14 +02:00
def models_to_list(models):
models_list = []
for model in models:
models_list.append(model.to_dict())
return models_list
2021-06-06 22:25:10 +02:00
@app.route("/")
def hello_world():
return "KI"
2021-06-07 17:52:14 +02:00
@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