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") })
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") })
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") })