forked from s434786/DINO_SCRUM
fix changeQuantity
This commit is contained in:
parent
37cdc842ea
commit
45dea34ef2
@ -52,7 +52,9 @@ public class Product {
|
|||||||
private String imageLink;
|
private String imageLink;
|
||||||
|
|
||||||
public Product setChangeQuantity(long change) {
|
public Product setChangeQuantity(long change) {
|
||||||
|
System.out.println("IN MODEL quantity: " + this.getQuantity() + " change" + change);
|
||||||
this.quantity += change;
|
this.quantity += change;
|
||||||
|
System.out.println("IN MODEL after change quantity: " + this.getQuantity());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,12 @@ public class ProductServiceImpl implements ProductService {
|
|||||||
@Override
|
@Override
|
||||||
public Product changeQuantity(QuantityChange quantityChange) throws Exception {
|
public Product changeQuantity(QuantityChange quantityChange) throws Exception {
|
||||||
productValidator.checkIfExists(quantityChange.getId());
|
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
|
@Override
|
||||||
|
@ -29,6 +29,7 @@ public class ProductValidator {
|
|||||||
public void checkIfExists(long id) throws Exception {
|
public void checkIfExists(long id) throws Exception {
|
||||||
if (!existsById(id))
|
if (!existsById(id))
|
||||||
throw new Exception("Product with id: " + id + " not found");
|
throw new Exception("Product with id: " + id + " not found");
|
||||||
|
System.out.println(id + " exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkIfExists(String name) throws Exception {
|
public void checkIfExists(String name) throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user