Category rendering, DB columns refined.

This commit is contained in:
2026-02-04 18:09:33 +07:00
parent d0b2a78618
commit 0e95c2986a
16 changed files with 215 additions and 15 deletions

18
services/categories.py Normal file
View File

@@ -0,0 +1,18 @@
from typing import Optional
from sqlalchemy.ext.asyncio import AsyncSession
from dto.categories import CategoryDTO
from repositories import CategoriesRepository
class CategoryService:
def __init__(self, category_repo: CategoriesRepository):
self.category_repo = category_repo
async def get_children(
self, session: AsyncSession, parent_id: Optional[int] = None
) -> list[CategoryDTO]:
result = await self.category_repo.get_category_by_parent_id(session, parent_id)
return [
CategoryDTO(x.id, x.name) for x in result
] # FIXME: Optimization may be required here - O(n)