Esempio n. 1
0
    def add_book():
        """Add a book to the library"""

        new_book = Book()

        if request.method == 'POST':
            data = request.get_json(force=True)
            new_book.title = data.get('book_title')
            new_book.publisher = data.get('publisher')
            new_book.publication_year = data.get('publication_year')
            new_book.edition = data.get('edition')
            new_book.category = data.get('category')
            new_book.subcategory = data.get('subcategory')
            new_book.description = data.get('description')

            new_book.save()

            return jsonify(new_book.serialize()), 201
Esempio n. 2
0
    def book_update_delete(book_id):
        """Update or delete a specific book with a given id"""

        book = Book().get_by_id(book_id)

        if not book:
            return jsonify({'message':
                            'The requested book was not found'}), 404

        if request.method == 'DELETE':
            book.delete()
            return jsonify({'message': 'Successfully deleted'}), 204

        elif request.method == 'PUT':
            data = request.get_json(force=True)
            book.title = data.get('book_title')
            book.publisher = data.get('publisher')
            book.publication_year = data.get('publication_year')
            book.edition = data.get('publisher')
            book.category = data.get('category')
            book.subcategory = data.get('subcategory')
            book.description = data.get('description')

            return jsonify(book.serialize()), 200