def get(self, questionid): """route to get a single question by id and all the available answers""" db = Database() questions = db.get_by_argument('questions', 'question_id', questionid) if questions: question = { "question_id": questions[0], "title": questions[2], "description": questions[3], "date posted": str(questions[4]) } answers = db.query_all_where_id('answers', 'question_id', questionid) answerlist = [] for ans in answers: answerdic = { "answer_id": ans[0], "question_id": ans[1], "user_id": ans[2], "answer": ans[3], "preffered": ans[4], "up_vote": ans[5], "down_vote": ans[6] } answerlist.append(answerdic) return {"question": question, "answers": answerlist}, 200 return {"message": "no question by that id"}, 400
def get(self): """all questions by the current user""" db = Database() user_id = get_jwt_identity() questions = db.query_all_where_id("questions", "user_id", user_id) if questions: user_qst = [] for qst in questions: question = { "question_id": qst[0], "user_id": qst[1], "title": qst[2], "description": qst[3], "date": str(qst[4]) } user_qst.append(question) return { "total_questions": len(user_qst), "questions": user_qst }, 200 return {"total_questions": 0}, 200
def get(self): """all answers by the current user""" db = Database() user_id = get_jwt_identity() answers = db.query_all_where_id("answers", "user_id", user_id) if answers: ans_list = [] for ans in answers: answerdic = { "answer_id": ans[0], "question_id": ans[1], "user_id": ans[2], "answer": ans[3], "preffered": ans[4], "up_vote": ans[5], "down_vote": ans[6] } ans_list.append(answerdic) return { "total_answers": len(ans_list), "user_answers": ans_list }, 200 return {"total_answers": 0}, 200