From e57e4e11d81803479b828237e24aa2d99a25f12e Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Thu, 5 Mar 2026 11:02:04 -0700 Subject: [PATCH] Make inventory storeId optional --- .../backend/service/InventoryService.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/petshop/backend/service/InventoryService.java b/src/main/java/com/petshop/backend/service/InventoryService.java index 9b2b0fe6..e144e67b 100644 --- a/src/main/java/com/petshop/backend/service/InventoryService.java +++ b/src/main/java/com/petshop/backend/service/InventoryService.java @@ -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);