Implementing Code Review comments -3
This commit is contained in:
parent
75df0b0778
commit
6092afb60a
@ -50,9 +50,4 @@ public class ProductController {
|
|||||||
return productService.findProductByName(name);
|
return productService.findProductByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/category")
|
|
||||||
public List<Product> getByCategory(@RequestParam String category) {
|
|
||||||
return productService.getProductsOfCategory(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,4 @@ import java.util.List;
|
|||||||
public interface ProductRepository extends CosmosRepository<Product, String> {
|
public interface ProductRepository extends CosmosRepository<Product, String> {
|
||||||
List<Product> findByProductName(String productName);
|
List<Product> findByProductName(String productName);
|
||||||
|
|
||||||
List<Product> findByProductCategory(String category);
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import java.util.Optional;
|
|||||||
public class ProductService {
|
public class ProductService {
|
||||||
|
|
||||||
private ProductRepository repository;
|
private ProductRepository repository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ProductService(ProductRepository repository) {
|
public ProductService(ProductRepository repository) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
@ -28,10 +28,6 @@ public class ProductService {
|
|||||||
return repository.findById(productId, new PartitionKey(category));
|
return repository.findById(productId, new PartitionKey(category));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Product> getProductsOfCategory(String category) {
|
|
||||||
return repository.findByProductCategory(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveProduct(Product product) {
|
public void saveProduct(Product product) {
|
||||||
repository.save(product);
|
repository.save(product);
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class AzurecosmodbApplicationManualTest {
|
public class AzurecosmodbApplicationManualTest {
|
||||||
|
|
||||||
@ -26,8 +24,9 @@ public class AzurecosmodbApplicationManualTest {
|
|||||||
product.setProductName("Blue Shirt");
|
product.setProductName("Blue Shirt");
|
||||||
|
|
||||||
productRepository.save(product);
|
productRepository.save(product);
|
||||||
Optional<Product> retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt"));
|
Product retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt"))
|
||||||
Assert.notNull(retrievedProduct.get(), "Retrieved Product is Null");
|
.orElse(null);
|
||||||
|
Assert.notNull(retrievedProduct, "Retrieved Product is Null");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user