Compare commits

...

3 Commits

4 changed files with 47 additions and 4 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ from typing import Optional
# Конфигурация # Конфигурация
USERNAME = "admin" USERNAME = "admin"
PASSWORD = "7WaVlcj8EWzEbbdab9kqRw" PASSWORD = "TzUlDpUCHutFa-oGCd1cBw"
BASE_URL = "http://localhost:8000" BASE_URL = "http://localhost:8000"
+5 -1
View File
@@ -1,6 +1,7 @@
"""Модуль DB-моделей книг""" """Модуль DB-моделей книг"""
from typing import TYPE_CHECKING, List from typing import TYPE_CHECKING, List
from sqlalchemy import Column, String
from sqlmodel import Field, Relationship from sqlmodel import Field, Relationship
from library_service.models.dto.book import BookBase from library_service.models.dto.book import BookBase
@@ -15,7 +16,10 @@ if TYPE_CHECKING:
class Book(BookBase, table=True): class Book(BookBase, table=True):
"""Модель книги в базе данных""" """Модель книги в базе данных"""
id: int | None = Field(default=None, primary_key=True, index=True) id: int | None = Field(default=None, primary_key=True, index=True)
status: BookStatus = Field(default=BookStatus.ACTIVE) status: BookStatus = Field(
default=BookStatus.ACTIVE,
sa_column=Column(String, nullable=False, default="active")
)
authors: List["Author"] = Relationship( authors: List["Author"] = Relationship(
back_populates="books", link_model=AuthorBookLink back_populates="books", link_model=AuthorBookLink
) )
+41 -1
View File
@@ -5,6 +5,11 @@ $(document).ready(() => {
let pageSize = 20; let pageSize = 20;
let totalBooks = 0; let totalBooks = 0;
const urlParams = new URLSearchParams(window.location.search);
const genreIdsFromUrl = urlParams.getAll("genre_id");
const authorIdsFromUrl = urlParams.getAll("author_id");
const searchFromUrl = urlParams.get("q");
Promise.all([ Promise.all([
fetch("/api/authors").then((response) => response.json()), fetch("/api/authors").then((response) => response.json()),
fetch("/api/genres").then((response) => response.json()), fetch("/api/genres").then((response) => response.json()),
@@ -18,15 +23,25 @@ $(document).ready(() => {
.attr("data-name", author.name) .attr("data-name", author.name)
.text(author.name) .text(author.name)
.appendTo($dropdown); .appendTo($dropdown);
if (authorIdsFromUrl.includes(String(author.id))) {
selectedAuthors.set(author.id, author.name);
}
}); });
const $list = $("#genres-list"); const $list = $("#genres-list");
genresData.genres.forEach((genre) => { genresData.genres.forEach((genre) => {
const isChecked = genreIdsFromUrl.includes(String(genre.id));
if (isChecked) {
selectedGenres.set(genre.id, genre.name);
}
$("<li>") $("<li>")
.addClass("mb-1") .addClass("mb-1")
.html( .html(
`<label class="custom-checkbox flex items-center"> `<label class="custom-checkbox flex items-center">
<input type="checkbox" data-id="${genre.id}" data-name="${genre.name}" /> <input type="checkbox" data-id="${genre.id}" data-name="${genre.name}" ${isChecked ? 'checked' : ''} />
<span class="checkmark"></span> <span class="checkmark"></span>
${genre.name} ${genre.name}
</label>`, </label>`,
@@ -57,6 +72,29 @@ $(document).ready(() => {
params.append("genre_ids", id); params.append("genre_ids", id);
}); });
function updateBrowserUrl() {
const params = new URLSearchParams();
const searchQuery = $("#book-search-input").val().trim();
if (searchQuery.length >= 3) {
params.append("q", searchQuery);
}
selectedAuthors.forEach((name, id) => {
params.append("author_id", id);
});
selectedGenres.forEach((name, id) => {
params.append("genre_id", id);
});
const newUrl = params.toString()
? `${window.location.pathname}?${params.toString()}`
: window.location.pathname;
window.history.replaceState({}, "", newUrl);
}
params.append("page", currentPage); params.append("page", currentPage);
params.append("size", pageSize); params.append("size", pageSize);
@@ -64,6 +102,8 @@ $(document).ready(() => {
showLoadingState(); showLoadingState();
updateBrowserUrl();
fetch(url) fetch(url)
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
-1
View File
@@ -22,7 +22,6 @@
<li><a href="/" class="hover:text-gray-200">Главная</a></li> <li><a href="/" class="hover:text-gray-200">Главная</a></li>
<li><a href="/books" class="hover:text-gray-200">Книги</a></li> <li><a href="/books" class="hover:text-gray-200">Книги</a></li>
<li><a href="/authors" class="hover:text-gray-200">Авторы</a></li> <li><a href="/authors" class="hover:text-gray-200">Авторы</a></li>
<li><a href="/about" class="hover:text-gray-200">О нас</a></li>
<li><a href="/api" class="hover:text-gray-200">API</a></li> <li><a href="/api" class="hover:text-gray-200">API</a></li>
</ul> </ul>
</nav> </nav>