Exemplo n.º 1
0
def add_book(name, author, price, img):
    """
	Add a student to the database, given
	their name, year, and whether they have
	finished the lab.
	"""
    Book_object = Books(title=name, price=price, authorname=author, pic=img)
    session.add(Book_object)
    session.commit()
Exemplo n.º 2
0
@auth.error_handler
def unauthorized():
    return make_response(jsonify({'error': 'Unauthorized access'}), 403)


@app.errorhandler(400)
def bad_request(error):
    return make_response(jsonify({'error': 'Bad request'}), 400)


@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)


lib = Books(books)


#get all books
@app.route('/api/books', methods=['GET'])
def get_books():
    return jsonify(lib.get_all()), 200


@app.route('/api/books/<int:book_id>', methods=['GET'])
def get_book(book_id):
    return jsonify(lib.get_bookbyid(book_id)), 200


#add  book
@app.route('/api/books', methods=['POST'])