| Line 126... |
Line 126... |
| 126 |
|
126 |
|
| 127 |
}
|
127 |
}
|
| 128 |
|
128 |
|
| 129 |
@Override
|
129 |
@Override
|
| 130 |
public boolean clearCart(int cartId) throws ProfitMandiBusinessException {
|
130 |
public boolean clearCart(int cartId) throws ProfitMandiBusinessException {
|
| - |
|
131 |
// Acquire pessimistic lock on cart to prevent deadlocks with concurrent requests
|
| - |
|
132 |
Cart cart = cartRepository.selectByIdForUpdate(cartId);
|
| 131 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
133 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 132 |
cartLines.stream().forEach(cartLine -> cartLineRepository.delete(cartLine));
|
134 |
cartLines.stream().forEach(cartLine -> cartLineRepository.delete(cartLine));
|
| 133 |
Cart cart = cartRepository.selectById(cartId);
|
- |
|
| 134 |
|
135 |
|
| 135 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
136 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
| 136 |
cart.setCheckoutTimestamp(null);
|
137 |
cart.setCheckoutTimestamp(null);
|
| 137 |
cart.setTotalPrice(0);
|
138 |
cart.setTotalPrice(0);
|
| 138 |
cart.setWalletAmount(0);
|
139 |
cart.setWalletAmount(0);
|
| Line 178... |
Line 179... |
| 178 |
* # No need to validate duplicate items since there are only two ways # to add
|
179 |
* # No need to validate duplicate items since there are only two ways # to add
|
| 179 |
* items to a cart and both of them check whether the item being # added is a
|
180 |
* items to a cart and both of them check whether the item being # added is a
|
| 180 |
* duplicate of an already existing item.
|
181 |
* duplicate of an already existing item.
|
| 181 |
*/
|
182 |
*/
|
| 182 |
|
183 |
|
| - |
|
184 |
// Acquire pessimistic lock on cart to prevent deadlocks with concurrent requests
|
| 183 |
Cart cart = cartRepository.selectById(cartId);
|
185 |
Cart cart = cartRepository.selectByIdForUpdate(cartId);
|
| 184 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
186 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 185 |
|
187 |
|
| 186 |
//User saholicUser = saholicUserRepository.selectByCartId(cartId);
|
188 |
//User saholicUser = saholicUserRepository.selectByCartId(cartId);
|
| 187 |
|
189 |
|
| 188 |
int totalQty = 0;
|
190 |
int totalQty = 0;
|
| Line 336... |
Line 338... |
| 336 |
return cartResponse;
|
338 |
return cartResponse;
|
| 337 |
}
|
339 |
}
|
| 338 |
|
340 |
|
| 339 |
@Override
|
341 |
@Override
|
| 340 |
public void addItemsToCart(int cartId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
342 |
public void addItemsToCart(int cartId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
| - |
|
343 |
// Acquire pessimistic lock on cart to prevent deadlocks with concurrent requests
|
| - |
|
344 |
cartRepository.selectByIdForUpdate(cartId);
|
| 341 |
logger.info("cart items {}", cartItems);
|
345 |
logger.info("cart items {}", cartItems);
|
| 342 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
346 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
| 343 |
Map<Integer, Integer> itemQuantityMap = cartItems.stream()
|
347 |
Map<Integer, Integer> itemQuantityMap = cartItems.stream()
|
| 344 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
348 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
| 345 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
349 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| Line 368... |
Line 372... |
| 368 |
|
372 |
|
| 369 |
}
|
373 |
}
|
| 370 |
|
374 |
|
| 371 |
@Override
|
375 |
@Override
|
| 372 |
public void addAddressToCart(int cartId, long addressId) throws ProfitMandiBusinessException {
|
376 |
public void addAddressToCart(int cartId, long addressId) throws ProfitMandiBusinessException {
|
| 373 |
Cart cart = cartRepository.selectById(cartId);
|
377 |
Cart cart = cartRepository.selectByIdForUpdate(cartId);
|
| 374 |
cart.setAddressId((int) addressId);
|
378 |
cart.setAddressId((int) addressId);
|
| 375 |
|
379 |
|
| 376 |
}
|
380 |
}
|
| 377 |
|
381 |
|
| 378 |
@Override
|
382 |
@Override
|
| Line 622... |
Line 626... |
| 622 |
logger.info("focusedModelShortageList {}", focusedModelShortageList);
|
626 |
logger.info("focusedModelShortageList {}", focusedModelShortageList);
|
| 623 |
return focusedModelShortageList;
|
627 |
return focusedModelShortageList;
|
| 624 |
}
|
628 |
}
|
| 625 |
|
629 |
|
| 626 |
@Override
|
630 |
@Override
|
| - |
|
631 |
public void updateCartItem(int cartId, int itemId, int quantity, float sellingPrice) throws ProfitMandiBusinessException {
|
| - |
|
632 |
cartRepository.selectByIdForUpdate(cartId);
|
| - |
|
633 |
CartLine cartLine = cartLineRepository.selectByCartItem(cartId, itemId);
|
| - |
|
634 |
if (quantity <= 0) {
|
| - |
|
635 |
if (cartLine != null) {
|
| - |
|
636 |
cartLineRepository.delete(cartLine);
|
| - |
|
637 |
}
|
| - |
|
638 |
} else if (cartLine == null) {
|
| - |
|
639 |
CartLine newLine = new CartLine();
|
| - |
|
640 |
newLine.setCartId(cartId);
|
| - |
|
641 |
newLine.setItemId(itemId);
|
| - |
|
642 |
newLine.setQuantity(quantity);
|
| - |
|
643 |
newLine.setActualPrice(sellingPrice);
|
| - |
|
644 |
newLine.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
645 |
newLine.setEstimate(2);
|
| - |
|
646 |
cartLineRepository.persist(newLine);
|
| - |
|
647 |
} else {
|
| - |
|
648 |
cartLine.setQuantity(quantity);
|
| - |
|
649 |
cartLine.setActualPrice(sellingPrice);
|
| - |
|
650 |
cartLine.setUpdateTimestapm(LocalDateTime.now());
|
| - |
|
651 |
}
|
| - |
|
652 |
}
|
| - |
|
653 |
|
| - |
|
654 |
@Override
|
| - |
|
655 |
public void removeCartItem(int cartId, int itemId) throws ProfitMandiBusinessException {
|
| - |
|
656 |
cartRepository.selectByIdForUpdate(cartId);
|
| - |
|
657 |
CartLine cartLine = cartLineRepository.selectByCartItem(cartId, itemId);
|
| - |
|
658 |
if (cartLine != null) {
|
| - |
|
659 |
cartLineRepository.delete(cartLine);
|
| - |
|
660 |
}
|
| - |
|
661 |
}
|
| - |
|
662 |
|
| - |
|
663 |
@Override
|
| - |
|
664 |
public List<CartLine> getCartItems(int cartId) throws ProfitMandiBusinessException {
|
| - |
|
665 |
return cartLineRepository.selectAllByCart(cartId);
|
| - |
|
666 |
}
|
| - |
|
667 |
|
| - |
|
668 |
@Override
|
| 627 |
public UserCart setCartItems(int fofoId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
669 |
public UserCart setCartItems(int fofoId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
| 628 |
User user = saholicUserRepository.selectById(fofoId);
|
670 |
User user = saholicUserRepository.selectById(fofoId);
|
| 629 |
this.clearCart(user.getActiveCartId());
|
671 |
this.clearCart(user.getActiveCartId());
|
| 630 |
this.addItemsToCart(user.getActiveCartId(), cartItems);
|
672 |
this.addItemsToCart(user.getActiveCartId(), cartItems);
|
| 631 |
|
673 |
|