Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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)
Exemplo n.º 5
0
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