def get_one_author(id): try: author = Author.get(id=id) return jsonify(author_schema.dump(author).data) except Author.DoesNotExist: return jsonify( {"message": "Can't find author with id - `{id}`".format(id=id)}), 404
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 get_authors(): groups = list(Author.select()) return jsonify(author_schema.dump(groups, many=True).data)
def read(): authors = list(Author.select()) return jsonify(author_schema.dump(authors, many=True).data)
def get_authors_of_book(id): authors = list( Author.select().join(AuthorBook).join(Book).where(Book.id == id)) return jsonify(author_schema.dump(authors, many=True)), 200