Fixed type hints, added cart item counter on main

This commit is contained in:
2026-02-08 13:31:28 +07:00
parent 9e96da8f53
commit e8a61c05b3
5 changed files with 57 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select, update
from typing import Optional
from db.models.orders import OrderItem
from db.models.orders import Order, OrderItem
class OrderItemRepository:
@@ -12,6 +12,14 @@ class OrderItemRepository:
stmt = select(OrderItem).where(OrderItem.id == item_id)
return await session.scalar(stmt)
async def get_items_by_order(
self, session: AsyncSession, order_id: int
) -> list[OrderItem]:
stmt = select(OrderItem).where(OrderItem.order_id == order_id)
result = await session.scalars(stmt)
return list(result)
async def get_item_by_order_and_product(
self, session: AsyncSession, *, order_id: int, product_id: int
) -> Optional[OrderItem]: