Files
shveitechbot/services/categories.py

19 lines
637 B
Python

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)