コード例 #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 post(self, quiz_id):
        data = parser.parse_args()
        data['quiz_id'] = quiz_id

        question = QuestionModel(**data)
        try:
            question.save()
        except:
            return {
                "message": "An error occurred while inserting Question."
            }, 500

        return question.json(), 201