Implementing Code Review comments -3

This commit is contained in:
Ankur Gupta 2020-08-01 22:41:28 +05:30
parent 75df0b0778
commit 6092afb60a
4 changed files with 4 additions and 15 deletions

View File

@ -50,9 +50,4 @@ public class ProductController {
return productService.findProductByName(name);
}
@GetMapping(value = "/category")
public List<Product> getByCategory(@RequestParam String category) {
return productService.getProductsOfCategory(category);
}
}

View File

@ -11,5 +11,4 @@ import java.util.List;
public interface ProductRepository extends CosmosRepository<Product, String> {
List<Product> findByProductName(String productName);
List<Product> findByProductCategory(String category);
}

View File

@ -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<Product> getProductsOfCategory(String category) {
return repository.findByProductCategory(category);
}
public void saveProduct(Product product) {
repository.save(product);
}

View File

@ -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<Product> 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");
}