diff --git a/backend/src/main/java/edu/zut/bookrider/service/QuoteService.java b/backend/src/main/java/edu/zut/bookrider/service/QuoteService.java index 5d9e6bf9..bf03990b 100644 --- a/backend/src/main/java/edu/zut/bookrider/service/QuoteService.java +++ b/backend/src/main/java/edu/zut/bookrider/service/QuoteService.java @@ -57,7 +57,7 @@ public QuoteResponseDTO generateQuote(Integer bookId, List options = new ArrayList<>(); for (Library library : libraries) { - boolean isLibraryInCart = isLibraryInCart(library, cart, bookId); + boolean isLibraryInCart = isLibraryInCart(library, cart); QuoteOption option = quoteOptionService.createQuoteOption( library, @@ -88,9 +88,10 @@ public QuoteResponseDTO generateQuote(Integer bookId, return quoteMapper.map(savedQuote); } - private boolean isLibraryInCart(Library library, ShoppingCart cart, Integer bookId) { + private boolean isLibraryInCart(Library library, ShoppingCart cart) { return cart.getItems().stream() - .anyMatch(item -> item.getLibrary().getId().equals(library.getId()) && - item.getBooks().stream().anyMatch(subItem -> subItem.getBook().getId().equals(bookId))); + .anyMatch(item -> item.getLibrary() != null + && item.getLibrary().getId() != null + && item.getLibrary().getId().equals(library.getId())); } }