diff --git a/models.py b/models.py index bd73c60..3de4e16 100644 --- a/models.py +++ b/models.py @@ -18,6 +18,7 @@ class Book(Base): id: Mapped[int] = mapped_column(primary_key=True, index=True) title: Mapped[str] = mapped_column(String(255), index=True) author: Mapped[str] = mapped_column(String(255)) + publisher: Mapped[str] = mapped_column(String(255), nullable=False) # Pydantic models class BookIn(BaseModel): @@ -25,6 +26,7 @@ class BookIn(BaseModel): title: str author: str + publisher: str = "" class BookOut(BaseModel): @@ -33,5 +35,6 @@ class BookOut(BaseModel): id: int title: str author: str + publisher: str model_config = ConfigDict(from_attributes=True) diff --git a/repositories.py b/repositories.py index dc9ff88..4fa11e7 100644 --- a/repositories.py +++ b/repositories.py @@ -4,7 +4,7 @@ # Create a new book def create_book(db: Session, book: models.BookIn): - db_book = models.Book(title=book.title, author=book.author) + db_book = models.Book(title=book.title, author=book.author, publisher=book.publisher) db.add(db_book) db.commit() db.refresh(db_book) @@ -27,6 +27,7 @@ def update_book(db: Session, book_id: int, book: models.BookIn): if db_book: db_book.title = book.title db_book.author = book.author + db_book.publisher = book.publisher db.commit() db.refresh(db_book) return db_book