示例#1
0
def get_author(author_id: int):
    author = Author.query.get_or_404(
        author_id, description=f"Author with id {author_id} not found!")
    return jsonify({
        'success': True,
        'data': author_schema.dump(author),
    })
def create_author(user_id: int, args: dict):
    author = Author(**args)

    db.session.add(author)
    db.session.commit()

    return jsonify({'success': True, 'data': author_schema.dump(author)}), 201
示例#3
0
def update_author(args: dict, author_id: int):
    author = Author.query.get_or_404(
        author_id, description=f'Author with id {author_id} not found')

    author.first_name = args["first_name"]
    author.last_name = args["last_name"]
    author.birth_date = args["birth_date"]
    db.session.commit()

    return jsonify({'success': True, 'data': author_schema.dump(author)})
def create_author(user_id: int, args: dict):
    author = Author(**args)

    # data = request.get_json()
    # first_name = data.get('first_name')
    # last_name = data.get('last_name')
    # birth_date = data.get('birth_date')
    # author = Author(first_name=first_name, last_name=last_name, birth_date=birth_date)
    db.session.add(author)
    db.session.commit()
    # print(author)

    return jsonify({'success': True, 'data': author_schema.dump(author)}), 201