def get(cls):
     '''get all questions'''
     limit = request.args.get('limit')
     if limit:
         limit = ast.literal_eval(limit)
     query = request.args.get('query')
     pages = request.args.get('pages')
     if pages:
         pages = ast.literal_eval(pages)
     my_question = QuestionsModel()
     if query == "most_answers":
         result = my_question.get_all_questions(limit,
                                                pages,
                                                most_answers=True)
     else:
         result = my_question.get_all_questions(limit, pages)
     all_questions = []
     for i in result:
         question = dict(id=i[0],
                         title=i[1],
                         content=i[2],
                         username=i[3],
                         answers_given=i[5])
         all_questions.append(question)
     return all_questions, 200
 def delete(cls, question_id):
     '''delete single question'''
     username = get_jwt_identity()
     q_id = ast.literal_eval(question_id)
     my_question = QuestionsModel()
     result = my_question.delete_question(q_id, username)
     return result["response"], result["status_code"]
 def get(cls):
     '''get all user's questions'''
     limit = request.args.get('limit')
     pages = request.args.get('pages')
     if limit:
         limit = ast.literal_eval(limit)
     if pages:
         pages = ast.literal_eval(pages)
     username = get_jwt_identity()
     my_question = QuestionsModel()
     result = my_question.get_all_user_questions(username, limit, pages)
     all_questions = []
     for i in result:
         question = {"question_id": i[0], "title": i[1], "content": i[2], "answers": i[5]}
         all_questions.append(question)
     return all_questions, 200
 def post(cls):
     '''post a question'''
     data = request.get_json()
     result = validate.check_for_data(data)
     if not result:
         title = data.get("title")
         content = data.get("content")
         result = validate.check_for_content([title, content])
         if not result:
             result = validate.check_for_white_spaces([title, content])
             if not result:
                 username = get_jwt_identity()
                 my_question = QuestionsModel()
                 result2 = my_question.post_question(
                     title, content, username)
                 return result2["response"], result2["status_code"]
     return result, 400
 def post(cls):
     '''search question'''
     limit = request.args.get('limit')
     if not limit:
         return dict(message="Enter a limit to search through"), 400
     limit = ast.literal_eval(limit)
     data = request.get_json()
     result = validate.check_for_data(data)
     if not result:
         content = data.get("content")
         result = validate.check_for_content([content])
         if not result:
             result = validate.check_for_white_spaces([content])
             if not result:
                 my_question = QuestionsModel()
                 result2 = my_question.search_question(content, limit)
                 return result2["response"], result2["status_code"]
     return result, 400
 def get(cls, question_id):
     '''get single question'''
     q_id = ast.literal_eval(question_id)
     my_question = QuestionsModel()
     result = my_question.get_single_question(q_id)
     return result["response"], result["status_code"]
 def get(cls):
     '''get all user's answers'''
     username = get_jwt_identity()
     my_question = QuestionsModel()
     return my_question.get_all_user_answers(username)