Product rendering, cart functionality

This commit is contained in:
2026-02-08 12:40:04 +07:00
parent d8cad25f33
commit 9e96da8f53
9 changed files with 399 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from typing import Optional
from db.models import Order
from db.models import Order, OrderStatus
class OrderRepository:
@@ -13,9 +13,33 @@ class OrderRepository:
return await session.scalar(stmt)
async def get_orders_by_user(
self, session: AsyncSession, user_id: int
self, session: AsyncSession, customer: int
) -> list[Order]:
stmt = select(Order).where(Order.customer == user_id)
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]:
stmt = (
select(Order)
.where(Order.customer == customer)
.where(Order.status == OrderStatus.DRAFT)
.limit(1)
)
return await session.scalar(stmt)
async def create_order(
self,
session: AsyncSession,
customer: int,
status: OrderStatus = OrderStatus.DRAFT,
):
order = Order(customer=customer, status=status)
session.add(order)
await session.commit()
return order