mirror of
https://github.com/wowlikon/LiB.git
synced 2026-02-04 12:31:09 +00:00
Добавление количества страниц книгам
This commit is contained in:
@@ -1,43 +1,55 @@
|
||||
"""Модуль DTO-моделей книг"""
|
||||
|
||||
from typing import List
|
||||
|
||||
from pydantic import ConfigDict
|
||||
from sqlmodel import SQLModel
|
||||
from sqlmodel import SQLModel, Field
|
||||
|
||||
from library_service.models.enums import BookStatus
|
||||
|
||||
|
||||
class BookBase(SQLModel):
|
||||
"""Базовая модель книги"""
|
||||
|
||||
title: str
|
||||
description: str
|
||||
page_count: int = Field(gt=0)
|
||||
|
||||
model_config = ConfigDict( # pyright: ignore
|
||||
json_schema_extra={
|
||||
"example": {"title": "book_title", "description": "book_description"}
|
||||
"example": {
|
||||
"title": "book_title",
|
||||
"description": "book_description",
|
||||
"page_count": 1,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class BookCreate(BookBase):
|
||||
"""Модель книги для создания"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class BookUpdate(SQLModel):
|
||||
"""Модель книги для обновления"""
|
||||
|
||||
title: str | None = None
|
||||
description: str | None = None
|
||||
page_count: int | None = None
|
||||
status: BookStatus | None = None
|
||||
|
||||
|
||||
class BookRead(BookBase):
|
||||
"""Модель книги для чтения"""
|
||||
|
||||
id: int
|
||||
status: BookStatus
|
||||
|
||||
|
||||
class BookList(SQLModel):
|
||||
"""Список книг"""
|
||||
|
||||
books: List[BookRead]
|
||||
total: int
|
||||
|
||||
@@ -37,6 +37,7 @@ class BookWithAuthors(SQLModel):
|
||||
id: int
|
||||
title: str
|
||||
description: str
|
||||
page_count: int
|
||||
authors: List[AuthorRead] = Field(default_factory=list)
|
||||
|
||||
|
||||
@@ -46,6 +47,7 @@ class BookWithGenres(SQLModel):
|
||||
id: int
|
||||
title: str
|
||||
description: str
|
||||
page_count: int
|
||||
status: BookStatus | None = None
|
||||
genres: List[GenreRead] = Field(default_factory=list)
|
||||
|
||||
@@ -56,6 +58,7 @@ class BookWithAuthorsAndGenres(SQLModel):
|
||||
id: int
|
||||
title: str
|
||||
description: str
|
||||
page_count: int
|
||||
status: BookStatus | None = None
|
||||
authors: List[AuthorRead] = Field(default_factory=list)
|
||||
genres: List[GenreRead] = Field(default_factory=list)
|
||||
|
||||
Reference in New Issue
Block a user