chore: minor fixes and formatting

This commit is contained in:
2026-08-12 19:52:30 +07:00
parent a011b2724b
commit ca276cdd61
48 changed files with 394 additions and 354 deletions

View File

@@ -1,11 +1,10 @@
from typing import Union, Optional
from sqlalchemy.ext.asyncio import AsyncSession
from config import PAGE_SIZE
from dto.catalogue import CatalogueType, CatalogueView
from misc.mapper import parse_cat_id, serialize_cat_id
from misc.texts import get_breadcrumps_path
from repositories import ProductRepository, CategoriesRepository
from config import PAGE_SIZE
from repositories import CategoriesRepository, ProductRepository
class CatalogueService:
@@ -16,14 +15,17 @@ class CatalogueService:
self.categories_repo = categories_repo
async def build_category_view(
self, session: AsyncSession, cat_id: Optional[Union[int, str]], page: int = 0
self,
session: AsyncSession,
cat_id: int | str | None,
page: int = 0,
*,
include_hidden: bool = False,
) -> CatalogueView:
cat_id = parse_cat_id(cat_id)
view = CatalogueView(page=page)
children = await self.categories_repo.get_categories_by_parent_id(
session, cat_id
)
children = await self.categories_repo.get_categories_by_parent_id(session, cat_id)
category = await self.categories_repo.get_category_by_id(session, cat_id)
if not category: # Root category
@@ -35,7 +37,11 @@ class CatalogueService:
if not children: # Products
products = await self.product_repo.get_product_by_category(
session, cat_id, limit=PAGE_SIZE + 1, offset=view.page * PAGE_SIZE
session,
cat_id,
limit=PAGE_SIZE + 1,
offset=view.page * PAGE_SIZE,
include_hidden=include_hidden,
)
if products:
view.view_type = CatalogueType.PRODUCTS
@@ -51,7 +57,7 @@ class CatalogueService:
return view
async def get_path(self, session: AsyncSession, cat_id: Union[int, str]):
async def get_path(self, session: AsyncSession, cat_id: int | str):
category = int(cat_id) if isinstance(cat_id, int) or cat_id.isdigit() else None
products = await self.categories_repo.get_category_path(session, category)