Make inventory storeId optional

This commit is contained in:
2026-03-05 11:02:04 -07:00
parent 9ae6ddc48e
commit e57e4e11d8

View File

@@ -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);