added request query kat_id for /fragen

This commit is contained in:
Pit-Storm 2019-08-31 22:25:45 +02:00
parent 17872668db
commit d86e9d0d6f
2 changed files with 22 additions and 3 deletions

View file

@ -3,5 +3,10 @@
"id": 0,
"text": "Dies ist eine Dummy Frage für Testzwecke",
"kategorie_id": 0
},
{
"id": 1,
"text": "Eine weitere Testfrage",
"kategorie_id": 0
}
]

View file

@ -1,4 +1,6 @@
from flask import Flask
from flask import request
import json
app = Flask(__name__)
@ -8,10 +10,22 @@ def root():
return "Candymat Data Backend"
@app.route('/fragen')
@app.route('/fragen/')
def fragen():
with open('data/fragen.json', 'r') as json_file:
return json_file.read()
with open('data/fragen.json', 'r', encoding="utf-8") as json_file:
fragen = json.load(json_file)
# Get the url Request Parameter "kat_id"
kat_id = request.args.get('kat_id')
if kat_id == None:
return json.dumps(fragen)
else:
answer = []
for frage in fragen:
if json.dumps(frage["kategorie_id"] )== kat_id:
answer.append(frage)
return json.dumps(answer)
@app.route('/kandidaten')