def get_one_book(id): try: book = Book.get(id=id) return jsonify(book_schema.dump(book).data) except Book.DoesNotExist: return jsonify( {"message": "Can't find book with id - `{id}`".format(id=id)}), 404
def create_book(): student, errors = book_schema.load(request.json) if errors: return jsonify(errors), 400 student.save() return jsonify(book_schema.dump(student).data), 201
def create_book(): book, errors = book_schema.load(request.json) if errors: return jsonify(errors), 400 book.save() return jsonify(book_schema.dump(book).data), 201
def create(): book, errors = book_schema.load(request.json) if errors: return jsonify(errors), 400 book.save() for author in request.json["authors"]: if not author_book_schema.validate({ "book": book.get_id(), "author": author }): AuthorBook.create(book=book, author=Author.get(id=author)) return jsonify(book_schema.dump(book).data), 201
def get_books(): return jsonify(book_schema.dump(list(Book.select()), many=True).data)
def get_books_of_author(id): books = list( Book.select().join(AuthorBook).join(Author).where(Author.id == id)) return jsonify(book_schema.dump(books, many=True)), 200