1
0
forked from s434786/DINO_SCRUM

fix changeQuantity

This commit is contained in:
prgres 2019-01-22 18:20:02 +01:00
parent 37cdc842ea
commit 45dea34ef2
3 changed files with 9 additions and 1 deletions

View File

@ -52,7 +52,9 @@ public class Product {
private String imageLink;
public Product setChangeQuantity(long change) {
System.out.println("IN MODEL quantity: " + this.getQuantity() + " change" + change);
this.quantity += change;
System.out.println("IN MODEL after change quantity: " + this.getQuantity());
return this;
}

View File

@ -43,7 +43,12 @@ public class ProductServiceImpl implements ProductService {
@Override
public Product changeQuantity(QuantityChange quantityChange) throws Exception {
productValidator.checkIfExists(quantityChange.getId());
return productRepository.findById(quantityChange.getId()).setChangeQuantity(quantityChange.getChange());
System.out.println("id: " + quantityChange.getId() + " change: " + quantityChange.getChange());
Product product = productRepository.findById(quantityChange.getId());
product.setChangeQuantity(quantityChange.getChange());
productRepository.save(product);
return productRepository.findById(quantityChange.getId());
}
@Override

View File

@ -29,6 +29,7 @@ public class ProductValidator {
public void checkIfExists(long id) throws Exception {
if (!existsById(id))
throw new Exception("Product with id: " + id + " not found");
System.out.println(id + " exists");
}
public void checkIfExists(String name) throws Exception {