chore: minor fixes and formatting

This commit is contained in:
2026-08-12 19:52:30 +07:00
parent a011b2724b
commit ca276cdd61
48 changed files with 394 additions and 354 deletions

View File

@@ -1,26 +1,18 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import delete, func, select
from typing import Optional
from sqlalchemy.ext.asyncio import AsyncSession
from db.models.orders import Order, OrderItem, OrderStatus
class OrderItemRepository:
async def get_item_by_id(
self, session: AsyncSession, item_id: int
) -> Optional[OrderItem]:
async def get_item_by_id(self, session: AsyncSession, item_id: int) -> OrderItem | None:
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, limit: int, offset: int = 0
) -> list[OrderItem]:
stmt = (
select(OrderItem)
.where(OrderItem.order_id == order_id)
.limit(limit)
.offset(offset)
)
stmt = select(OrderItem).where(OrderItem.order_id == order_id).limit(limit).offset(offset)
result = await session.scalars(stmt)
return list(result)
@@ -29,9 +21,7 @@ class OrderItemRepository:
stmt = select(func.count(OrderItem.id)).where(OrderItem.order_id == order_id)
return await session.scalar(stmt) or 0
async def get_items_count_by_customer(
self, session: AsyncSession, customer: int
) -> int:
async def get_items_count_by_customer(self, session: AsyncSession, customer: int) -> int:
count = await session.scalar(
select(func.count(OrderItem.id))
.join(Order)
@@ -44,7 +34,7 @@ class OrderItemRepository:
async def get_item_by_order_and_product(
self, session: AsyncSession, *, order_id: int, product_id: int
) -> Optional[OrderItem]:
) -> OrderItem | None:
stmt = (
select(OrderItem)
.where(OrderItem.order_id == order_id)
@@ -68,9 +58,7 @@ class OrderItemRepository:
product_id: int,
quantity: int = 1,
) -> OrderItem:
order_item = OrderItem(
order_id=order_id, product_id=product_id, quantity=quantity
)
order_item = OrderItem(order_id=order_id, product_id=product_id, quantity=quantity)
session.add(order_item)
await session.commit()