def create_author(): author, errors = author_schema.load(request.json) if errors: return jsonify(errors), 400 author.save() return jsonify(author_schema.dump(author).data), 201
def update_author(id): try: author = Author.get(id=id) except Author.DoesNotExist: return jsonify( {"message": "Can't find author with id - `{id}`".format(id=id)}), 404 author, errors = author_schema.load(request.json, instance=author) if errors: return jsonify(errors), 400 author.save() return jsonify(book_schema.dumps(author).data), 200