Make inventory storeId optional
This commit is contained in:
@@ -51,9 +51,11 @@ public class InventoryService {
|
|||||||
Product product = productRepository.findById(request.getProdId())
|
Product product = productRepository.findById(request.getProdId())
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId()));
|
.orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId()));
|
||||||
|
|
||||||
Long storeId = request.getStoreId() != null ? request.getStoreId() : 1L;
|
Store store = null;
|
||||||
Store store = storeRepository.findById(storeId)
|
if (request.getStoreId() != null) {
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId));
|
store = storeRepository.findById(request.getStoreId())
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId()));
|
||||||
|
}
|
||||||
|
|
||||||
Inventory inventory = new Inventory();
|
Inventory inventory = new Inventory();
|
||||||
inventory.setProduct(product);
|
inventory.setProduct(product);
|
||||||
@@ -74,9 +76,11 @@ public class InventoryService {
|
|||||||
Product product = productRepository.findById(request.getProdId())
|
Product product = productRepository.findById(request.getProdId())
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId()));
|
.orElseThrow(() -> new ResourceNotFoundException("Product not found with id: " + request.getProdId()));
|
||||||
|
|
||||||
Long storeId = request.getStoreId() != null ? request.getStoreId() : 1L;
|
Store store = null;
|
||||||
Store store = storeRepository.findById(storeId)
|
if (request.getStoreId() != null) {
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + storeId));
|
store = storeRepository.findById(request.getStoreId())
|
||||||
|
.orElseThrow(() -> new ResourceNotFoundException("Store not found with id: " + request.getStoreId()));
|
||||||
|
}
|
||||||
|
|
||||||
inventory.setProduct(product);
|
inventory.setProduct(product);
|
||||||
inventory.setStore(store);
|
inventory.setStore(store);
|
||||||
|
|||||||
Reference in New Issue
Block a user