def sign_up(cls): data = request.validate({ "email": "required|email|unique:users", "password": "******", "name": "required|min_length:3" }) return jsonify(dict(data=User.create(data))), 201
def update(cls, question_id, answer_id): answer = Answer.by_question_id(question_id, answer_id).update( request.validate({ "body": "required" })) return jsonify(dict(data=answer)), 200
def update(cls, id): question = Question.find_or_fail(id) if not User.owns_question(question): return jsonify({"error": "Access denied for updating question"}), 401 return jsonify( {"data": question.update(request.validate(validation_rules))})
def login(cls): data = request.validate({ "email": "required|email", "password": "******", }) return jsonify({ "token": User.auth().issue_token(data), "message": "Authentication was successful" })
def update(cls, question_id, answer_id): answer = Answer.find_or_fail(answer_id) if User.owns_answer(answer): answer.update(request.validate({"body": "required"})) return jsonify(dict(data=answer)), 200 question = Question.find_or_fail(question_id) if User.owns_question(question): question.update(dict(prefered_answer_id=answer_id)) return jsonify(dict(message="Answer marked as the preferred")), 200 return jsonify(dict(error="Access denied for updating answer")), 401
def store(cls): return jsonify( {"data": Question.create(request.validate(validation_rules))}), 201
def store(cls, question_id): question = Question.find_or_fail(question_id) answer = question.answers().create(request.validate({ "body": "required" })) return jsonify(dict(data=answer)), 201
def update(cls, id): return jsonify({ "data": Question.find_or_fail(id).update( request.validate(validation_rules)) })