mirror of
https://github.com/kristoferssolo/LU-bookstore.git
synced 2025-10-21 18:00:34 +00:00
feat(Inventory): update add method
This commit is contained in:
parent
a78734252c
commit
f0087b97ce
@ -29,14 +29,15 @@ class Inventory:
|
|||||||
"""Close database connection."""
|
"""Close database connection."""
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
def add(self, book: Book) -> None:
|
def add(self, *books: list[Book]) -> None:
|
||||||
"""Add `Book` to the `Inventory`. `Book`s ISBN must be unique."""
|
"""Add `Book` to the `Inventory`. `Book`s ISBN must be unique."""
|
||||||
try:
|
for book in books:
|
||||||
self.cursor.execute("INSERT INTO Book VALUES (?, ?, ?, ?, ?)", (book.isbn, book.title, book.author, book.price, book.stock))
|
try:
|
||||||
self.conn.commit()
|
self.cursor.execute("INSERT INTO Book VALUES (?, ?, ?, ?, ?)", (book.isbn, book.title, book.author, book.price, book.stock))
|
||||||
print(f"Book with ISBN: {book.isbn} was saved")
|
self.conn.commit()
|
||||||
except sqlite3.InternalError:
|
print(f"Book with ISBN: {book.isbn} was saved")
|
||||||
print(f"A book with ISBN {book.isbn} already exists in the database.")
|
except sqlite3.InternalError:
|
||||||
|
print(f"A book with ISBN {book.isbn} already exists in the database.")
|
||||||
|
|
||||||
def delete(self, isbn: ISBN) -> Book | None:
|
def delete(self, isbn: ISBN) -> Book | None:
|
||||||
"""Deletes `Book` from `Inventory` by `ISBN` and returns deleted `Book`"""
|
"""Deletes `Book` from `Inventory` by `ISBN` and returns deleted `Book`"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user