コード例 #1
0
    def put(self, quiz_id, question_id):
        data = parser.parse_args()
        data['quiz_id'] = quiz_id

        question = QuestionModel.find_by_id(question_id)

        if question is None:
            new_question = QuestionModel(**data)
            try:
                new_question.save()

                return new_question.json(), 201
            except:
                return {
                    "message": "An error occurred while inserting Question."
                }, 500

        try:
            question.update(**data)
        except:
            return {
                "message": "An error occurred while updating Question."
            }, 500

        return question.json(), 200
コード例 #2
0
    def delete(self, question_id):
        question = QuestionModel.find_by_id(question_id)
        if question:
            question.delete_from_db()
            return {'message': 'Question deleted'}

        return {'message': 'Question not found'}
コード例 #3
0
    def get(self, quiz_id, question_id):
        question = QuestionModel.find_by_id(question_id)

        if question is None:
            return {"message": "No question found."}, 404

        return question.json(), 200
コード例 #4
0
    def post(self, id):
        if QuestionModel.find_by_id(id):
            return {
                'message': "A question with id '{}' already exists.".format(id)
            }, 400

        question = QuestionModel(id)
        try:
            question.save_to_db()
        except:
            return {"message": "An error occurred creating the question."}, 500

        return question.json(), 201
コード例 #5
0
    def delete(self, quiz_id, question_id):
        question = QuestionModel.find_by_id(question_id)

        if question is None:
            return {"message": "No question found."}, 404

        try:
            question.delete()
        except:
            return {
                "message": "An error occurred while deleting Question."
            }, 500

        return {"message": "Question deleted."}, 200
コード例 #6
0
    def put(self, question_id):
        data = Question.parser.parse_args()

        question = QuestionModel.find_by_id(question_id)

        if question is None:  # Create a new question if it does not exist in the database
            question = QuestionModel(**data)
        else:  # Update the question if it exists in the database
            question.quiz_id = data['quiz_id']
            question.question_category = data['question_category']
            question.questiontype_id = data['questiontype_id']
            question.question_statement = data['question_statement']
            question.question_correct_entries = data[
                'question_correct_entries']
            question.question_wrong_entries = data['question_wrong_entries']
            question.question_update = datetime.now()

        question.save_to_db()

        return question.json()
コード例 #7
0
    def get(self, _id=None):
        question = QuestionModel.find_by_id(_id)  # really (?)
        if question:
            return question.json(), 200

        return dict(message='Question not found'.format(_id)), 404
コード例 #8
0
 def get(self, id):
     question = QuestionModel.find_by_id(id)
     if question:
         return question.json()
     return {'message': 'Question not found'}, 404
コード例 #9
0
    def delete(self, id):
        question = QuestionModel.find_by_id(id)
        if question:
            question.delete_from_db()

        return {'message': 'question deleted'}