Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/app/app_layer/use_cases/cart_items/add_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ async def execute(self, data: AddItemToCartInputDTO) -> CartOutputDTO:
async def _add_item_to_cart(self, data: AddItemToCartInputDTO) -> CartOutputDTO:
user = await self._auth_system.get_user_data(auth_data=data.auth_data)

async with self._uow(autocommit=True):
async with self._uow(autocommit=False):
cart = await self._uow.carts.retrieve(cart_id=data.cart_id)
await self._uow.commit()

self._check_user_ownership(cart=cart, user=user)
cart = await self._update_cart(cart=cart, data=data)
self._check_user_ownership(cart=cart, user=user)
cart = await self._update_cart(cart=cart, data=data)

await self._uow.commit()

return CartOutputDTO.model_validate(cart)

Expand All @@ -80,9 +83,7 @@ async def _try_to_add_new_item_to_cart(
) -> Cart:
item = await self._try_to_create_item(cart=cart, data=data)
cart.add_new_item(item)

async with self._uow(autocommit=True):
await self._uow.items.add_item(item=item)
await self._uow.items.add_item(item=item)

logger.info(
"Item %s successfully added to cart %s with qty %s",
Expand Down Expand Up @@ -113,9 +114,7 @@ async def _try_to_create_item(

async def _increase_item_qty(self, cart: Cart, item_id: int, qty: Decimal) -> Cart:
item = cart.increase_item_qty(item_id=item_id, qty=qty)

async with self._uow(autocommit=True):
await self._uow.items.update_item(item=item)
await self._uow.items.update_item(item=item)

logger.info(
"Cart %s. Item %s qty successfully increased. Current item qty %s",
Expand Down