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

View File

@@ -0,0 +1,21 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from typing import Optional
from db.models import Category
class CategoriesRepository:
async def get_category_by_id(
self, session: AsyncSession, category_id: int
) -> Optional[Category]:
stmt = select(Category).where(Category.id == category_id)
return await session.scalar(stmt)
async def get_category_by_parent_id(
self, session: AsyncSession, parent_id: Optional[int] = None
) -> list[Category]:
stmt = select(Category).where(Category.parent_id == parent_id)
result = await session.scalars(stmt)
return list(result)