diff --git a/company-service/src/main/java/com/shipflow/companyservice/application/client/ProductFeignClient.java b/company-service/src/main/java/com/shipflow/companyservice/application/client/ProductFeignClient.java index d2498bf..00ab305 100644 --- a/company-service/src/main/java/com/shipflow/companyservice/application/client/ProductFeignClient.java +++ b/company-service/src/main/java/com/shipflow/companyservice/application/client/ProductFeignClient.java @@ -11,8 +11,8 @@ @FeignClient(name = "product-service") public interface ProductFeignClient { @DeleteMapping("/internal/companies/{companyId}/products/deactivate") - Void deleteProductByCompanyId(@PathVariable("companyId") UUID companyId); + Void deleteProductsByCompanyId(@PathVariable("companyId") UUID companyId); @DeleteMapping("/internal/companies/products/deactivate/bulk") - Void deleteProductsByCompanyIds(@RequestBody List companyIds); + Void deleteProductsByCompanyIdList(@RequestBody List companyIds); } diff --git a/company-service/src/main/java/com/shipflow/companyservice/application/service/CompanyService.java b/company-service/src/main/java/com/shipflow/companyservice/application/service/CompanyService.java index a8f9cc8..ce4e86f 100644 --- a/company-service/src/main/java/com/shipflow/companyservice/application/service/CompanyService.java +++ b/company-service/src/main/java/com/shipflow/companyservice/application/service/CompanyService.java @@ -61,7 +61,7 @@ public void deleteCompany(UUID companyId) { Company company = findCompanyById(companyId); company.delete(deleterId); companyRepository.save(company); - productFeignClient.deleteProductByCompanyId(companyId); + productFeignClient.deleteProductsByCompanyId(companyId); } @Transactional @@ -143,7 +143,15 @@ public void deleteProductsByHub(UUID hubId) { company.delete(UserContext.getUserId()); companyRepository.save(company); }); - productFeignClient.deleteProductsByCompanyIds(companyIds); + productFeignClient.deleteProductsByCompanyIdList(companyIds); + } + + @Transactional + public void deleteProductByUser(UUID userId) { + Company company = findCompanyByManagerId(userId); + company.delete(UserContext.getUserId()); + companyRepository.save(company); + productFeignClient.deleteProductsByCompanyId(company.getId()); } diff --git a/company-service/src/main/java/com/shipflow/companyservice/presentation/controller/CompanyInternalController.java b/company-service/src/main/java/com/shipflow/companyservice/presentation/controller/CompanyInternalController.java index 00ed07b..e62b8ce 100644 --- a/company-service/src/main/java/com/shipflow/companyservice/presentation/controller/CompanyInternalController.java +++ b/company-service/src/main/java/com/shipflow/companyservice/presentation/controller/CompanyInternalController.java @@ -29,4 +29,9 @@ public VendorInfoResponse getVendorById(@PathVariable("companyId") UUID companyI public void deleteByHub(@PathVariable("hubId") UUID hubId) { companyService.deleteProductsByHub(hubId); } + + @DeleteMapping("/user/{userId}") + public void deleteByUser(@PathVariable("userId") UUID userId) { + companyService.deleteProductByUser(userId); + } } diff --git a/product-service/src/main/java/com/shipflow/productservice/application/service/ProductService.java b/product-service/src/main/java/com/shipflow/productservice/application/service/ProductService.java index 6a782c1..a61f5e8 100644 --- a/product-service/src/main/java/com/shipflow/productservice/application/service/ProductService.java +++ b/product-service/src/main/java/com/shipflow/productservice/application/service/ProductService.java @@ -74,7 +74,7 @@ public void delete(UUID productId, UUID companyId) { validateAuth(companyId); UUID deleterId = UserContext.getUserId(); - Product product = findProductById(productId); + Product product = validateProductOwnership(productId, companyId); product.delete(deleterId); productRepository.save(product); @@ -173,10 +173,8 @@ public StockInfoResponse getStockInfoAndOccupy(@Param("productId") UUID productI .orElseThrow(() -> new BusinessException(CommonErrorCode.INTERNAL_SERVER_ERROR)); if(currentStock<0){ - Long restoreStock=redisTemplate.opsForValue().increment(stockKey, (long)quantity); - return new StockInfoResponse(productId, product.getName(), product.getCompanyId(), - product.getCompanyName(), product.getHubId(), - restoreStock != null ? restoreStock.intValue() : currentStock.intValue()); + redisTemplate.opsForValue().increment(stockKey, (long)quantity); + throw new BusinessException(ProductErrorCode.EXCEEDS_STOCK_LEVEL); } redisTemplate.opsForValue().set(occupancyKey, quantity, Duration.ofSeconds(5)); diff --git a/user-service/src/main/java/com/shipflow/userservice/infrastructure/client/CompanyFeignClient.java b/user-service/src/main/java/com/shipflow/userservice/infrastructure/client/CompanyFeignClient.java index 6d010fa..8d46061 100644 --- a/user-service/src/main/java/com/shipflow/userservice/infrastructure/client/CompanyFeignClient.java +++ b/user-service/src/main/java/com/shipflow/userservice/infrastructure/client/CompanyFeignClient.java @@ -8,6 +8,6 @@ @FeignClient(name = "company-service") public interface CompanyFeignClient { - @DeleteMapping("/internal/companies/{userId}") + @DeleteMapping("/internal/companies/user/{userId}") ClientApiResponse deleteManager(@PathVariable UUID userId); }