diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java index fe02be88ff..25f88bac72 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java @@ -50,9 +50,4 @@ public class ProductController { return productService.findProductByName(name); } - @GetMapping(value = "/category") - public List getByCategory(@RequestParam String category) { - return productService.getProductsOfCategory(category); - } - } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java index 29dc85a2cf..1e4a2987a1 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java @@ -11,5 +11,4 @@ import java.util.List; public interface ProductRepository extends CosmosRepository { List findByProductName(String productName); - List findByProductCategory(String category); } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java index 49d07ca5a2..0d1cf7c6a6 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java @@ -14,7 +14,7 @@ import java.util.Optional; public class ProductService { private ProductRepository repository; - + @Autowired public ProductService(ProductRepository repository) { this.repository = repository; @@ -28,10 +28,6 @@ public class ProductService { return repository.findById(productId, new PartitionKey(category)); } - public List getProductsOfCategory(String category) { - return repository.findByProductCategory(category); - } - public void saveProduct(Product product) { repository.save(product); } diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java index 786b578501..7ebdce279b 100644 --- a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java +++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java @@ -9,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.util.Assert; -import java.util.Optional; - @SpringBootTest public class AzurecosmodbApplicationManualTest { @@ -26,8 +24,9 @@ public class AzurecosmodbApplicationManualTest { product.setProductName("Blue Shirt"); productRepository.save(product); - Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")); - Assert.notNull(retrievedProduct.get(), "Retrieved Product is Null"); + Product retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")) + .orElse(null); + Assert.notNull(retrievedProduct, "Retrieved Product is Null"); }