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