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,30 +1,22 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import delete, select
from typing import Optional
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from db.models import Order, OrderStatus, OrderItem
from db.models import Order, OrderItem, OrderStatus
class OrderRepository:
async def get_order_by_id(
self, session: AsyncSession, order_id: int
) -> Optional[Order]:
async def get_order_by_id(self, session: AsyncSession, order_id: int) -> Order | None:
stmt = select(Order).where(Order.id == order_id)
return await session.scalar(stmt)
async def get_orders_by_user(
self, session: AsyncSession, customer: int
) -> list[Order]:
async def get_orders_by_user(self, session: AsyncSession, customer: int) -> list[Order]:
stmt = select(Order).where(Order.customer == customer)
result = await session.scalars(stmt)
return list(result)
async def get_draft_order_by_user(
self, session: AsyncSession, customer: int
) -> Optional[Order]:
async def get_draft_order_by_user(self, session: AsyncSession, customer: int) -> Order | None:
stmt = (
select(Order)
.where(Order.customer == customer)
@@ -59,9 +51,7 @@ class OrderRepository:
await session.execute(stmt)
await session.commit()
async def update_order_status(
self, session: AsyncSession, order_id: int, status: OrderStatus
):
async def update_order_status(self, session: AsyncSession, order_id: int, status: OrderStatus):
order = await self.get_order_by_id(session, order_id)
order.status = status