mirror of
https://github.com/wowlikon/LibraryAPI.git
synced 2025-12-11 21:30:46 +00:00
Форматирование кода, добавление лого, исправление тестов, улучшение эндпоинтов и документации
This commit is contained in:
@@ -2,16 +2,24 @@ from .author import Author
|
||||
from .book import Book
|
||||
from .genre import Genre
|
||||
from .links import (
|
||||
AuthorBookLink, GenreBookLink,
|
||||
AuthorWithBooks, BookWithAuthors,
|
||||
GenreWithBooks, BookWithGenres,
|
||||
BookWithAuthorsAndGenres
|
||||
AuthorBookLink,
|
||||
GenreBookLink,
|
||||
AuthorWithBooks,
|
||||
BookWithAuthors,
|
||||
GenreWithBooks,
|
||||
BookWithGenres,
|
||||
BookWithAuthorsAndGenres,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'Author', 'Book', 'Genre',
|
||||
'AuthorBookLink', 'AuthorWithBooks',
|
||||
'BookWithAuthors', 'GenreBookLink',
|
||||
'GenreWithBooks', 'BookWithGenres',
|
||||
'BookWithAuthorsAndGenres'
|
||||
"Author",
|
||||
"Book",
|
||||
"Genre",
|
||||
"AuthorBookLink",
|
||||
"AuthorWithBooks",
|
||||
"BookWithAuthors",
|
||||
"GenreBookLink",
|
||||
"GenreWithBooks",
|
||||
"BookWithGenres",
|
||||
"BookWithAuthorsAndGenres",
|
||||
]
|
||||
|
||||
@@ -6,9 +6,9 @@ from .links import AuthorBookLink
|
||||
if TYPE_CHECKING:
|
||||
from .book import Book
|
||||
|
||||
|
||||
class Author(AuthorBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True, index=True)
|
||||
books: List["Book"] = Relationship(
|
||||
back_populates="authors",
|
||||
link_model=AuthorBookLink
|
||||
back_populates="authors", link_model=AuthorBookLink
|
||||
)
|
||||
|
||||
@@ -7,13 +7,12 @@ if TYPE_CHECKING:
|
||||
from .author import Author
|
||||
from .genre import Genre
|
||||
|
||||
|
||||
class Book(BookBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True, index=True)
|
||||
authors: List["Author"] = Relationship(
|
||||
back_populates="books",
|
||||
link_model=AuthorBookLink
|
||||
back_populates="books", link_model=AuthorBookLink
|
||||
)
|
||||
genres: List["Genre"] = Relationship(
|
||||
back_populates="books",
|
||||
link_model=GenreBookLink
|
||||
back_populates="books", link_model=GenreBookLink
|
||||
)
|
||||
|
||||
@@ -6,9 +6,9 @@ from .links import GenreBookLink
|
||||
if TYPE_CHECKING:
|
||||
from .book import Book
|
||||
|
||||
|
||||
class Genre(GenreBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True, index=True)
|
||||
books: List["Book"] = Relationship(
|
||||
back_populates="genres",
|
||||
link_model=GenreBookLink
|
||||
back_populates="genres", link_model=GenreBookLink
|
||||
)
|
||||
|
||||
@@ -5,26 +5,35 @@ from library_service.models.dto.author import AuthorRead
|
||||
from library_service.models.dto.book import BookRead
|
||||
from library_service.models.dto.genre import GenreRead
|
||||
|
||||
|
||||
class AuthorBookLink(SQLModel, table=True):
|
||||
author_id: int | None = Field(default=None, foreign_key="author.id", primary_key=True)
|
||||
author_id: int | None = Field(
|
||||
default=None, foreign_key="author.id", primary_key=True
|
||||
)
|
||||
book_id: int | None = Field(default=None, foreign_key="book.id", primary_key=True)
|
||||
|
||||
|
||||
class GenreBookLink(SQLModel, table=True):
|
||||
genre_id: int | None = Field(default=None, foreign_key="genre.id", primary_key=True)
|
||||
book_id: int | None = Field(default=None, foreign_key="book.id", primary_key=True)
|
||||
|
||||
|
||||
class AuthorWithBooks(AuthorRead):
|
||||
books: List[BookRead] = Field(default_factory=list)
|
||||
|
||||
|
||||
class BookWithAuthors(BookRead):
|
||||
authors: List[AuthorRead] = Field(default_factory=list)
|
||||
|
||||
|
||||
class BookWithGenres(BookRead):
|
||||
genres: List[GenreRead] = Field(default_factory=list)
|
||||
|
||||
|
||||
class GenreWithBooks(GenreRead):
|
||||
books: List[BookRead] = Field(default_factory=list)
|
||||
|
||||
|
||||
class BookWithAuthorsAndGenres(BookRead):
|
||||
authors: List[AuthorRead] = Field(default_factory=list)
|
||||
genres: List[GenreRead] = Field(default_factory=list)
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
from .author import (
|
||||
AuthorBase, AuthorCreate, AuthorUpdate,
|
||||
AuthorRead, AuthorList
|
||||
)
|
||||
from .book import (
|
||||
BookBase, BookCreate, BookUpdate,
|
||||
BookRead, BookList
|
||||
)
|
||||
from .author import AuthorBase, AuthorCreate, AuthorUpdate, AuthorRead, AuthorList
|
||||
from .book import BookBase, BookCreate, BookUpdate, BookRead, BookList
|
||||
|
||||
from .genre import (
|
||||
GenreBase, GenreCreate, GenreUpdate,
|
||||
GenreRead, GenreList
|
||||
)
|
||||
from .genre import GenreBase, GenreCreate, GenreUpdate, GenreRead, GenreList
|
||||
|
||||
__all__ = [
|
||||
'AuthorBase', 'AuthorCreate', 'AuthorUpdate', 'AuthorRead', 'AuthorList',
|
||||
'BookBase', 'BookCreate', 'BookUpdate', 'BookRead', 'BookList',
|
||||
'GenreBase', 'GenreCreate', 'GenreUpdate', 'GenreRead', 'GenreList',
|
||||
"AuthorBase",
|
||||
"AuthorCreate",
|
||||
"AuthorUpdate",
|
||||
"AuthorRead",
|
||||
"AuthorList",
|
||||
"BookBase",
|
||||
"BookCreate",
|
||||
"BookUpdate",
|
||||
"BookRead",
|
||||
"BookList",
|
||||
"GenreBase",
|
||||
"GenreCreate",
|
||||
"GenreUpdate",
|
||||
"GenreRead",
|
||||
"GenreList",
|
||||
]
|
||||
|
||||
@@ -2,24 +2,27 @@ from sqlmodel import SQLModel
|
||||
from pydantic import ConfigDict
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class AuthorBase(SQLModel):
|
||||
name: str
|
||||
|
||||
model_config = ConfigDict( #pyright: ignore
|
||||
json_schema_extra={
|
||||
"example": {"name": "author_name"}
|
||||
}
|
||||
model_config = ConfigDict( # pyright: ignore
|
||||
json_schema_extra={"example": {"name": "author_name"}}
|
||||
)
|
||||
|
||||
|
||||
class AuthorCreate(AuthorBase):
|
||||
pass
|
||||
|
||||
|
||||
class AuthorUpdate(SQLModel):
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class AuthorRead(AuthorBase):
|
||||
id: int
|
||||
|
||||
|
||||
class AuthorList(SQLModel):
|
||||
authors: List[AuthorRead]
|
||||
total: int
|
||||
|
||||
@@ -2,29 +2,31 @@ from sqlmodel import SQLModel
|
||||
from pydantic import ConfigDict
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class BookBase(SQLModel):
|
||||
title: str
|
||||
description: str
|
||||
|
||||
model_config = ConfigDict( #pyright: ignore
|
||||
model_config = ConfigDict( # pyright: ignore
|
||||
json_schema_extra={
|
||||
"example": {
|
||||
"title": "book_title",
|
||||
"description": "book_description"
|
||||
}
|
||||
"example": {"title": "book_title", "description": "book_description"}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class BookCreate(BookBase):
|
||||
pass
|
||||
|
||||
|
||||
class BookUpdate(SQLModel):
|
||||
title: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
class BookRead(BookBase):
|
||||
id: int
|
||||
|
||||
|
||||
class BookList(SQLModel):
|
||||
books: List[BookRead]
|
||||
total: int
|
||||
|
||||
@@ -2,24 +2,27 @@ from sqlmodel import SQLModel
|
||||
from pydantic import ConfigDict
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
class GenreBase(SQLModel):
|
||||
name: str
|
||||
|
||||
model_config = ConfigDict( #pyright: ignore
|
||||
json_schema_extra={
|
||||
"example": {"name": "genre_name"}
|
||||
}
|
||||
model_config = ConfigDict( # pyright: ignore
|
||||
json_schema_extra={"example": {"name": "genre_name"}}
|
||||
)
|
||||
|
||||
|
||||
class GenreCreate(GenreBase):
|
||||
pass
|
||||
|
||||
|
||||
class GenreUpdate(SQLModel):
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class GenreRead(GenreBase):
|
||||
id: int
|
||||
|
||||
|
||||
class GenreList(SQLModel):
|
||||
genres: List[GenreRead]
|
||||
total: int
|
||||
|
||||
Reference in New Issue
Block a user