Skip to content

Commit 296a011

Browse files
BENCH-161 Changes reflecting Andrews observations
1 parent 7f7dc2e commit 296a011

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/main/java/com/answerdigital/academy/answerking/service/OrderService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public Order addProductToBasket(final Long orderId, final Long productId, final
6464
throw new ProductUnavailableException(String.format("The product with ID %d is not available.", product.getId()));
6565
}
6666

67-
final Optional<LineItem> existingOrderProduct = order.getLineItems()
67+
final Optional<LineItem> existingLineItem = order.getLineItems()
6868
.stream()
6969
.filter(lineItem -> lineItem.getProduct() == product)
7070
.findFirst();
7171

72-
if (existingOrderProduct.isPresent()) {
72+
if (existingLineItem.isPresent()) {
7373
throw new ConflictException(String.format("Product id %s is already in the basket", product.getId()));
7474
}
7575

@@ -102,18 +102,18 @@ public Order deleteProductInBasket(final Long orderId, final Long productId) {
102102
final Order order = findById(orderId);
103103
final Product product = productService.findById(productId);
104104

105-
final Optional<LineItem> existingOrderProduct = order.getLineItems()
105+
final Optional<LineItem> existingLineItem = order.getLineItems()
106106
.stream()
107107
.filter(lineItem -> lineItem.getProduct() == product)
108108
.findFirst();
109109

110-
if (existingOrderProduct.isEmpty()) {
110+
if (existingLineItem.isEmpty()) {
111111
throw new NotFoundException(
112112
String.format("Product id = %s is not in the basket of order id = %s", productId, orderId)
113113
);
114114
}
115115

116-
order.getLineItems().remove(existingOrderProduct.get());
116+
order.getLineItems().remove(existingLineItem.get());
117117
return orderRepository.save(order);
118118
}
119119
}

src/main/java/com/answerdigital/academy/answerking/service/ProductService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public ProductService(final ProductRepository productRepository) {
2525

2626
public Product addNewProduct(final ProductRequest productRequest) {
2727
if (productRepository.existsByName(productRequest.name())) {
28-
throw new ConflictException(String.format("An Product named '%s' already exists", productRequest.name()));
28+
throw new ConflictException(String.format("A Product named '%s' already exists", productRequest.name()));
2929
}
3030

3131
final Product newProduct = productMapper.addRequestToProduct(productRequest);
@@ -46,7 +46,7 @@ public Product updateProduct(final long productId, final ProductRequest productR
4646
.orElseThrow(() -> new NotFoundException(String.format("Product with ID %d does not exist.", productId)));
4747

4848
if (productRepository.existsByNameAndIdIsNot(productRequest.name(), productId)) {
49-
throw new ConflictException(String.format("An Product named '%s' already exists", productRequest.name()));
49+
throw new ConflictException(String.format("A Product named '%s' already exists", productRequest.name()));
5050
}
5151

5252
final Product updatedProduct = productMapper.updateRequestToProduct(findById(productId), productRequest);

0 commit comments

Comments
 (0)