def get(self, question_id): answers = Question.get_or_404(question_id).answers answer_schema = AnswerSchema(many=True, only=["id", "title", "answerer"]) return jsonify({ "data": answer_schema.dump(answers).data, "status": "success", "message": SUCCESS_MESSAGES["fetched"].format("Answers") })
def delete(self, question_id): question = Question.get_or_404(question_id) question.delete() return jsonify({ "status": "success", "message": SUCCESS_MESSAGES["deleted"].format("Question") })
def get(self, question_id): question = Question.get_or_404(question_id) question_schema = QuestionSchema(only=["title"]) return jsonify({ "data": question_schema.dump_object_into_schema(question), "status": "success", "message": SUCCESS_MESSAGES["fetched"].format("Question") })
def post(self, question_id): request_data = request.get_json() user = User.query.get("16") question = Question.get_or_404(question_id) answer_schema = AnswerSchema( only=["id", "title", "created_at", "updated_at", "parent_id"]) answer_data = answer_schema.load_object_into_schema(request_data) answer_data["answerer"] = user answer_data["answer"] = question answer_data["parent_id"] = 12 answer = Answer(**answer_data) answer.save() return jsonify({ "data": answer_schema.dump_object_into_schema(answer), "status": "success", "message": SUCCESS_MESSAGES["created"].format("Answer") })
def put(self, question_id): request_data = request.get_json() question = Question.get_or_404(question_id) question_schema = QuestionSchema(only=["title"]) question_data = question_schema.load_object_into_schema(request_data) print(request_data.get('title')) question = question.update(question_data) question.save() return jsonify({ "data": question_schema.dump_object_into_schema(question), "status": "success", "message": SUCCESS_MESSAGES["updated"].format("Question") })