-
Remco Tukker authoredRemco Tukker authored
survey.py 1.31 KiB
import logging
from flask import Blueprint, jsonify, request
from sqlalchemy import select
from compendium_v2.db import db
from compendium_v2.db.survey_model import Questions, Answers
from compendium_v2.routes import common
from typing import Any
routes = Blueprint('survey', __name__)
logger = logging.getLogger(__name__)
# TODO (partial) schemas
@routes.route('/open', methods=['GET'])
@common.require_accepts_json
def open_survey() -> Any:
entries = [entry for entry in db.session.scalars(select(Questions))]
entries2 = [entry for entry in db.session.scalars(select(Answers))]
# TODO check if the survey was already started, if so, continue with that survey:
# survey_continue = {
# "questions": entries,
# "data": "TODO",
# # TODO page number
# "unvalidated": ["TODO also take this from the db"] # TODO or maybe do it in another way..
# }
survey_start = {
"questions": entries,
"data": "TODO take from db last year",
"unvalidated": ["TODO list question names from last_year_data"] # TODO or maybe do it in another way..
}
return jsonify(survey_start)
@routes.route('/save', methods=['POST'])
@common.require_accepts_json
def save_survey() -> Any:
data = request.json
# TODO store stuff in db
return jsonify(data), 201