Implementing Code Review comments
This commit is contained in:
parent
b5eef05476
commit
23f1333aaa
|
@ -16,6 +16,7 @@
|
|||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<cosmodb.version>2.3.0</cosmodb.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -26,14 +27,17 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>spring-data-cosmosdb</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>${cosmodb.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -22,9 +22,13 @@ import java.util.Optional;
|
|||
@RequestMapping("/products")
|
||||
public class ProductController {
|
||||
|
||||
@Autowired
|
||||
private ProductService productService;
|
||||
|
||||
@Autowired
|
||||
public ProductController(ProductService productService) {
|
||||
this.productService = productService;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public void create(@RequestBody Product product) {
|
||||
|
@ -46,8 +50,8 @@ public class ProductController {
|
|||
return productService.findProductByName(name);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/category/{category}")
|
||||
public List<Product> getByCategory(@PathVariable String category) {
|
||||
@GetMapping(value = "/category")
|
||||
public List<Product> getByCategory(@RequestParam String category) {
|
||||
return productService.getProductsOfCategory(category);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,11 @@ import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
|
|||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Document(collection = "products")
|
||||
public class Product {
|
||||
|
||||
|
@ -18,41 +23,4 @@ public class Product {
|
|||
@PartitionKey
|
||||
private String productCategory;
|
||||
|
||||
public String getProductid() {
|
||||
return productid;
|
||||
}
|
||||
|
||||
public void setProductid(String productid) {
|
||||
this.productid = productid;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
|
||||
public String getProductCategory() {
|
||||
return productCategory;
|
||||
}
|
||||
|
||||
public void setProductCategory(String productCategory) {
|
||||
this.productCategory = productCategory;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Product [productid=" + productid + ", productName=" + productName + ", price=" + price + ", productCategory=" + productCategory + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ public class ProductService {
|
|||
}
|
||||
|
||||
public List<Product> getProductsOfCategory(String category) {
|
||||
List<Product> products = repository.findByProductCategory(category);
|
||||
return products;
|
||||
return repository.findByProductCategory(category);
|
||||
}
|
||||
|
||||
public void saveProduct(Product product) {
|
||||
|
|
|
@ -14,14 +14,14 @@ import java.util.Optional;
|
|||
//Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties
|
||||
//to run the integration test
|
||||
//@SpringBootTest
|
||||
public class AzurecosmodbApplicationIntegrationTest {
|
||||
public class AzurecosmodbApplicationManualTest {
|
||||
|
||||
@Autowired
|
||||
ProductRepository productRepository;
|
||||
|
||||
// Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties
|
||||
// to run the integration test
|
||||
// @Test
|
||||
//@Test
|
||||
public void givenProductIsCreated_whenCallFindById_thenProductIsFound() {
|
||||
Product product = new Product();
|
||||
product.setProductid("1001");
|
||||
|
@ -29,11 +29,9 @@ public class AzurecosmodbApplicationIntegrationTest {
|
|||
product.setPrice(110.0);
|
||||
product.setProductName("Blue Shirt");
|
||||
|
||||
// Uncomment these lines when configured URI and keys for Azure Cosmos DB in application.properties
|
||||
// to run the integration test
|
||||
// productRepository.save(product);
|
||||
// Optional<Product> retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt"));
|
||||
// Assert.notNull(retrievedProduct, "Retrieved Product is Null");
|
||||
productRepository.save(product);
|
||||
Optional<Product> retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt"));
|
||||
Assert.notNull(retrievedProduct, "Retrieved Product is Null");
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue