コード例 #1
0
    def put(self, book_id):
        data = Book.parser.parse_args()
        book = BookModel.findById(book_id)

        if book is None:
            book = BookModel(data['book_title'], data['book_description'],
                             data['book_genre'])
        else:
            book.book_title = data['book_title']
            book.book_description = data['book_description']
            book.book_genre = data['book_genre']
            book.book_update = datetime.now()

        book.saveToDb()
        return book.json()
コード例 #2
0
    def put(self, book_id):
        data = Book.parser.parse_args()

        book = BookModel.find_by_id(book_id)

        if book is None:  # Create a new book if it does not exist in the database
            book = BookModel(**data)
        else:  # Update the book if it exists in the database
            book.book_title = data['book_title']
            book.book_description = data['book_description']
            book.book_genre = data['book_genre']
            book.book_update = datetime.now()

        book.save_to_db()

        return book.json()