def create_answer(): data = request.get_json() or {} if check_body_response('response', 'question_id', data=data): return bad_request('must include describe and question_id fields') answer = Answer() answer.from_dict(data) response = make_response(answer, data) return response
def create_question(): data = request.get_json() or {} if check_body_response('name', 'describe', 'poll_id', data=data) is False: return bad_request('must include name and describe fields') if Question.query.filter_by(name=data['name']).first(): return bad_request('please use a different name') question = Question() question.from_dict(data) response = make_response(question, data) return response
def make_result(): print(g.current_user) data = request.get_json() or {} if check_body_response('poll_id', 'question_id', 'answer_id', data=data) is False: return bad_request('must include poll_id, question_id and answer_id fields') if Result.query.filter_by(user_id=g.current_user.id).filter_by(question_id=data['question_id']).first(): return bad_request('You have result for this question. Please use PUT method.') result = Result(user_id=g.current_user.id, poll_id=0, question_id=0, answer_id=0) result.from_dict(data) response = make_response(result, data) return response
def create_user(): data = request.get_json() or {} if check_body_response('username', 'email', 'password', data=data) is False: return bad_request('must include username, email and password fields') if User.query.filter_by(username=data['username']).first(): return bad_request('please use a different username') if User.query.filter_by(email=data['email']).first(): return bad_request('please use a different email address') user = User() user.from_dict(data, new_user=True) response = make_response(user, data) return response