Products Rendering, removal of deprecated files
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .orders import OrderRepository
|
||||
from .categories import CategoriesRepository
|
||||
from .products import ProductRepository
|
||||
|
||||
__all__ = ["OrderRepository", "CategoriesRepository"]
|
||||
__all__ = ["OrderRepository", "CategoriesRepository", "ProductRepository"]
|
||||
|
||||
@@ -12,7 +12,7 @@ class CategoriesRepository:
|
||||
stmt = select(Category).where(Category.id == category_id)
|
||||
return await session.scalar(stmt)
|
||||
|
||||
async def get_category_by_parent_id(
|
||||
async def get_categories_by_parent_id(
|
||||
self, session: AsyncSession, parent_id: Optional[int] = None
|
||||
) -> list[Category]:
|
||||
stmt = select(Category).where(Category.parent_id == parent_id)
|
||||
|
||||
28
repositories/products.py
Normal file
28
repositories/products.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from typing import Optional
|
||||
|
||||
from db.models import Product
|
||||
|
||||
|
||||
class ProductRepository:
|
||||
async def get_product_by_id(
|
||||
self, session: AsyncSession, product_id: int
|
||||
) -> Optional[Product]:
|
||||
stmt = select(Product).where(Product.id == product_id)
|
||||
return await session.scalar(stmt)
|
||||
|
||||
async def get_product_by_category(
|
||||
self, session: AsyncSession, category_id: int, *, limit: int, offset: int
|
||||
) -> list[Product]:
|
||||
stmt = (
|
||||
select(Product)
|
||||
.where(Product.category_id == category_id)
|
||||
.order_by(Product.id)
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
)
|
||||
|
||||
result = await session.scalars(stmt)
|
||||
|
||||
return list(result)
|
||||
Reference in New Issue
Block a user