| 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);
|
- |
|
| 133 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
131 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 134 |
cartLines.stream().forEach(cartLine -> cartLineRepository.delete(cartLine));
|
132 |
cartLines.stream().forEach(cartLine -> cartLineRepository.delete(cartLine));
|
| - |
|
133 |
Cart cart = cartRepository.selectById(cartId);
|
| 135 |
|
134 |
|
| 136 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
135 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
| 137 |
cart.setCheckoutTimestamp(null);
|
136 |
cart.setCheckoutTimestamp(null);
|
| 138 |
cart.setTotalPrice(0);
|
137 |
cart.setTotalPrice(0);
|
| 139 |
cart.setWalletAmount(0);
|
138 |
cart.setWalletAmount(0);
|
| Line 179... |
Line 178... |
| 179 |
* # No need to validate duplicate items since there are only two ways # to add
|
178 |
* # No need to validate duplicate items since there are only two ways # to add
|
| 180 |
* items to a cart and both of them check whether the item being # added is a
|
179 |
* items to a cart and both of them check whether the item being # added is a
|
| 181 |
* duplicate of an already existing item.
|
180 |
* duplicate of an already existing item.
|
| 182 |
*/
|
181 |
*/
|
| 183 |
|
182 |
|
| 184 |
// Acquire pessimistic lock on cart to prevent deadlocks with concurrent requests
|
- |
|
| 185 |
Cart cart = cartRepository.selectByIdForUpdate(cartId);
|
183 |
Cart cart = cartRepository.selectById(cartId);
|
| 186 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
184 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 187 |
|
185 |
|
| 188 |
//User saholicUser = saholicUserRepository.selectByCartId(cartId);
|
186 |
//User saholicUser = saholicUserRepository.selectByCartId(cartId);
|
| 189 |
|
187 |
|
| 190 |
int totalQty = 0;
|
188 |
int totalQty = 0;
|
| Line 338... |
Line 336... |
| 338 |
return cartResponse;
|
336 |
return cartResponse;
|
| 339 |
}
|
337 |
}
|
| 340 |
|
338 |
|
| 341 |
@Override
|
339 |
@Override
|
| 342 |
public void addItemsToCart(int cartId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
340 |
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);
|
- |
|
| 345 |
logger.info("cart items {}", cartItems);
|
341 |
logger.info("cart items {}", cartItems);
|
| 346 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
342 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
| 347 |
Map<Integer, Integer> itemQuantityMap = cartItems.stream()
|
343 |
Map<Integer, Integer> itemQuantityMap = cartItems.stream()
|
| 348 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
344 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
| 349 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
345 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| Line 372... |
Line 368... |
| 372 |
|
368 |
|
| 373 |
}
|
369 |
}
|
| 374 |
|
370 |
|
| 375 |
@Override
|
371 |
@Override
|
| 376 |
public void addAddressToCart(int cartId, long addressId) throws ProfitMandiBusinessException {
|
372 |
public void addAddressToCart(int cartId, long addressId) throws ProfitMandiBusinessException {
|
| 377 |
Cart cart = cartRepository.selectByIdForUpdate(cartId);
|
373 |
Cart cart = cartRepository.selectById(cartId);
|
| 378 |
cart.setAddressId((int) addressId);
|
374 |
cart.setAddressId((int) addressId);
|
| 379 |
|
375 |
|
| 380 |
}
|
376 |
}
|
| 381 |
|
377 |
|
| 382 |
@Override
|
378 |
@Override
|
| Line 626... |
Line 622... |
| 626 |
logger.info("focusedModelShortageList {}", focusedModelShortageList);
|
622 |
logger.info("focusedModelShortageList {}", focusedModelShortageList);
|
| 627 |
return focusedModelShortageList;
|
623 |
return focusedModelShortageList;
|
| 628 |
}
|
624 |
}
|
| 629 |
|
625 |
|
| 630 |
@Override
|
626 |
@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
|
- |
|
| 669 |
public UserCart setCartItems(int fofoId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
627 |
public UserCart setCartItems(int fofoId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
| 670 |
User user = saholicUserRepository.selectById(fofoId);
|
628 |
User user = saholicUserRepository.selectById(fofoId);
|
| 671 |
this.clearCart(user.getActiveCartId());
|
629 |
this.clearCart(user.getActiveCartId());
|
| 672 |
this.addItemsToCart(user.getActiveCartId(), cartItems);
|
630 |
this.addItemsToCart(user.getActiveCartId(), cartItems);
|
| 673 |
|
631 |
|