Ejemplo n.º 1
0
    def delete(self, question_id, answer_id):
        answer = Answer.get_or_404(answer_id)
        answer.delete()

        return jsonify({
            "status": "success",
            "message": SUCCESS_MESSAGES["deleted"].format("Answer")
        })
Ejemplo n.º 2
0
    def get(self, question_id, answer_id):
        answer = Answer.get_or_404(answer_id)

        answer_schema = AnswerSchema(
            only=["id", "title", "answerer", "children", "parent"])

        return jsonify({
            "data": answer_schema.dump_object_into_schema(answer),
            "status": "success",
            "message": SUCCESS_MESSAGES["fetched"].format("Answers")
        })
Ejemplo n.º 3
0
    def put(self, question_id, answer_id):
        request_data = request.get_json()

        answer = Answer.get_or_404(answer_id)

        answer_schema = AnswerSchema(only=["title"])
        answer_data = answer_schema.load_object_into_schema(request_data)

        answer = answer.update(answer_data)
        answer.save()

        return jsonify({
            "data": answer_schema.dump_object_into_schema(answer),
            "status": "success",
            "message": SUCCESS_MESSAGES["updated"].format("Answer")
        })