Skip to content

Commit

Permalink
Merge pull request #21 from duongminhhieu/feature
Browse files Browse the repository at this point in the history
refactor: check product isAvailable before create order
  • Loading branch information
duongminhhieu committed Jun 5, 2024
2 parents a13f061 + f0cadb8 commit aaf5cbc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
public interface CartItemRepository extends JpaRepository<CartItem, String>{
Optional<CartItem> findByProductAndUser(Product product, User user);
List<CartItem> findAllByUserOrderByLastModifiedDateDesc(User user);
List<CartItem> findAllByUserAndProductIsAvailable(User user, Boolean isAvailable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public OrderResponse create(OrderRequest orderRequest) {
User user = userRepository.findByEmail(email).orElseThrow(() -> new AppException(ErrorCode.USER_NOT_FOUND));

// get the cart items of the user
List<CartItem> cartItems = cartItemRepository.findAllByUserOrderByLastModifiedDateDesc(user);
List<CartItem> cartItems = cartItemRepository.findAllByUserAndProductIsAvailable(user, true);
Set<String> cartItemRequestIds = orderRequest.getCartItemIds();

// Extract IDs from cartItems
Expand Down

0 comments on commit aaf5cbc

Please sign in to comment.