Merge remote-tracking branch 'origin' into start-redaktions-app
This commit is contained in:
commit
e25fcf3442
12
README.md
12
README.md
|
@ -1 +1,13 @@
|
|||
# Candymat - Wahl-o-Mat fuer Personalwahlen
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Check-out repository
|
||||
* [Install git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
|
||||
* `git clone https://github.com/netzbegruenung/candymat.git`
|
||||
* To get the (external) user-app source:
|
||||
```
|
||||
git submodule init
|
||||
git submodule update
|
||||
```
|
||||
|
16
backend/data/antworten.json
Normal file
16
backend/data/antworten.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
[
|
||||
{
|
||||
"id": 0,
|
||||
"kandidaten_id": 0,
|
||||
"fragen_id": 0,
|
||||
"kategorien_id": 0,
|
||||
"text": "Lorem ipsum"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"kandidaten_id": 0,
|
||||
"fragen_id": 1,
|
||||
"kategorien_id": 0,
|
||||
"text": "Lorem ipsum..."
|
||||
}
|
||||
]
|
|
@ -3,5 +3,15 @@
|
|||
"id": 0,
|
||||
"text": "Dies ist eine Dummy Frage für Testzwecke",
|
||||
"kategorie_id": 0
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"text": "Eine weitere Testfrage",
|
||||
"kategorie_id": 0
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"text": "Die besondere Frage.",
|
||||
"kategorie_id": 1
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
[{
|
||||
"id": 0,
|
||||
"name": "Umwelt"
|
||||
}, {
|
||||
"id": 1,
|
||||
"name": "Soziales"
|
||||
}]
|
||||
[
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Umwelt"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Soziales"
|
||||
}
|
||||
]
|
|
@ -1,8 +1,21 @@
|
|||
from flask import Flask
|
||||
from flask import request
|
||||
import json
|
||||
|
||||
#########
|
||||
# Helper Functions
|
||||
|
||||
def get_kat_n(k_id):
|
||||
with open('data/kategorien.json', 'r', encoding="utf-8") as json_file:
|
||||
kategorien = json.load(json_file)
|
||||
|
||||
for kategorie in kategorien:
|
||||
if json.dumps(kategorie["id"]) == k_id:
|
||||
return kategorie["name"]
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route('/api/')
|
||||
def root():
|
||||
return "Candymat Data Backend"
|
||||
|
@ -10,8 +23,28 @@ def root():
|
|||
|
||||
@app.route('/api/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:
|
||||
answer = []
|
||||
|
||||
for frage in fragen:
|
||||
frage.update({"kategorie_name": get_kat_n(json.dumps(frage["kategorie_id"]))})
|
||||
frage.pop("kategorie_id")
|
||||
answer.append(frage)
|
||||
return json.dumps(answer)
|
||||
else:
|
||||
answer = []
|
||||
for frage in fragen:
|
||||
if json.dumps(frage["kategorie_id"]) == kat_id:
|
||||
frage.update({"kategorie_name": get_kat_n(json.dumps(frage["kategorie_id"]))})
|
||||
frage.pop("kategorie_id")
|
||||
answer.append(frage)
|
||||
return json.dumps(answer)
|
||||
|
||||
|
||||
@app.route('/api/kandidaten')
|
||||
|
@ -24,3 +57,8 @@ def kandidaten():
|
|||
def kategorien():
|
||||
with open('data/kategorien.json', 'r') as json_file:
|
||||
return json_file.read()
|
||||
|
||||
@app.route('/api/antworten')
|
||||
def antworten():
|
||||
with open('data/antworten.json','r') as json_file:
|
||||
return json_file.read()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
|
||||
from main import kandidaten, fragen, kategorien
|
||||
from main import kandidaten, fragen, kategorien, antworten
|
||||
|
||||
|
||||
def test_kandidaten():
|
||||
|
@ -24,9 +24,9 @@ def test_kandidaten():
|
|||
def test_fragen():
|
||||
expected_result = [
|
||||
{
|
||||
"id": 0,
|
||||
"text": "Dies ist eine Dummy Frage für Testzwecke",
|
||||
"kategorie_id": 0
|
||||
"id": 2,
|
||||
"text": "Die besondere Frage.",
|
||||
"kategorie_name": "Soziales"
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -43,3 +43,27 @@ def test_kategorien():
|
|||
}]
|
||||
|
||||
assert json.loads(kategorien()) == expected_result
|
||||
|
||||
def test_antworten():
|
||||
expected_result = [{
|
||||
{
|
||||
"id": 0,
|
||||
"kandidat_vorname": "Max",
|
||||
"kandidat_name": "Mustermann",
|
||||
"kandidat_email": "max.mustermann@yahoo.com"
|
||||
"frage_text": "Dies ist eine Dummy Frage für Testzwecke",
|
||||
"kategorie_name": "Umwelt",
|
||||
"antwort_text": "Lorem ipsum"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"kandidat_vorname": "Max",
|
||||
"kandidat_name": "Mustermann",
|
||||
"kandidat_email": "max.mustermann@yahoo.com"
|
||||
"frage_text": "Eine weitere Testfrage"
|
||||
"kategorie_name": "Umwelt",
|
||||
"antwort_text": "Lorem ipsum..."
|
||||
}
|
||||
}]
|
||||
|
||||
assert json.loads(antworten()) == expected_result
|
||||
|
|
Loading…
Reference in a new issue