def post_question(): question = Question( question=request.json.get("question"), answer=request.json.get("answer"), difficulty=request.json.get("difficulty"), category=request.json.get("category"), ) question.insert() return jsonify( dict( r, message="Successfully added question to database", data=question.format(), ))
def post_new_question(): body = request.get_json() new_content = body.get('question', None) new_answer = body.get('answer', None) new_category = body.get('category', None) new_score = body.get('score', None) search_term = body.get('search', None) if search_term is None: try: question = Question(question=new_content, answer=new_answer, category=new_category, difficulty=new_score) question.insert() return jsonify({ 'success': True, 'created': question.id, 'question': question, 'total_questions': len(Question.query.all()) }) except: abort(422) else: questions = Question.query.filter( Question.question.ilike('%' + search_term + '%')).all() if questions is None: abort(404) else: formatted_questions = [ question.format() for question in questions ] return jsonify({ 'success': True, 'questions': formatted_questions })