Пример #1
0
    def get_questions():
        questions = Question.get_by_page(request, QUESTIONS_PER_PAGE)

        if len(questions) == 0:
            abort(404)

        return jsonify({
            "questions": questions,
            "total_questions": len(Question.get_all()),
            "success": True,
            "categories": Category.to_dict(),
        })
Пример #2
0
    def create_question():
        data = request.get_json()
        question = Question(**data)
        result = question.insert_record()

        if result["error"]:
            abort(500)

        _id = result["id"]
        questions = Question.get_by_page(request, QUESTIONS_PER_PAGE)

        return jsonify({
            "created": _id,
            "questions": questions,
            "total_questions": len(Question.get_all()),
            "success": True,
        })
Пример #3
0
    def delete_question(question_id):
        question = Question.get_by_id(question_id)

        if question is None:
            abort(404)

        result = question.delete_record()

        if result["error"]:
            abort(500)

        questions = Question.get_by_page(request, QUESTIONS_PER_PAGE)

        return jsonify({
            "deleted": question_id,
            "questions": questions,
            "total_questions": len(Question.get_all()),
            "success": True,
        })