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,5 +1,7 @@
import logging
from sqlalchemy.ext.asyncio import AsyncSession
from config import PAGE_SIZE
from db.models.orders import OrderStatus
from dto.cart import CartDTO, CartItemDTO
@@ -9,13 +11,11 @@ from repositories.orders import OrderRepository
logger = logging.getLogger(__name__)
class OrderServiceException(Exception): ...
class OrderServiceError(Exception): ...
class OrderService:
def __init__(
self, order_repo: OrderRepository, order_items_repo: OrderItemRepository
):
def __init__(self, order_repo: OrderRepository, order_items_repo: OrderItemRepository):
self.order_repo = order_repo
self.order_items_repo = order_items_repo
@@ -34,9 +34,7 @@ class OrderService:
order = await self.order_repo.get_draft_order_by_user(session, customer)
if not order:
order = await self.order_repo.create_order(
session, customer, OrderStatus.DRAFT
)
order = await self.order_repo.create_order(session, customer, OrderStatus.DRAFT)
order_item = await self.order_items_repo.get_item_by_order_and_product(
session, order_id=order.id, product_id=product_id
@@ -65,7 +63,7 @@ class OrderService:
order = await self.order_repo.get_draft_order_by_user(session, customer)
if not order:
raise OrderServiceException(
raise OrderServiceError(
"attempt of removing product from non-existing cart, potential callback_query exploit, ignoring..."
)
@@ -74,7 +72,7 @@ class OrderService:
)
if not order_item:
raise OrderServiceException(
raise OrderServiceError(
"attempt of decreasing quantity of non-existing order_item, potential callback_query exploit, ignoring..."
)
@@ -88,13 +86,11 @@ class OrderService:
return new_quantity
async def clear_from_cart(
self, session: AsyncSession, *, customer: int, product_id: int
):
async def clear_from_cart(self, session: AsyncSession, *, customer: int, product_id: int):
order = await self.order_repo.get_draft_order_by_user(session, customer)
if not order:
raise OrderServiceException(
raise OrderServiceError(
"attempt of removing product from non-existing cart, potential callback_query exploit, ignoring..."
)
@@ -103,7 +99,7 @@ class OrderService:
)
if not order_item:
raise OrderServiceException(
raise OrderServiceError(
"attempt of decreasing quantity of non-existing order_item, potential callback_query exploit, ignoring..."
)
@@ -162,9 +158,7 @@ class OrderService:
return CartDTO(items=cart_items, total=total, order_id=order.id)
async def build_full_cart_dto(
self, session: AsyncSession, customer: int
) -> CartDTO:
async def build_full_cart_dto(self, session: AsyncSession, customer: int) -> CartDTO:
order = await self.order_repo.get_draft_order_by_user(session, customer)
cart_items = []