Implementing Code Review comments
This commit is contained in:
parent
b5eef05476
commit
23f1333aaa
|
@ -1,48 +1,52 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-cosmosdb</artifactId>
|
||||
<name>spring-data-cosmos-db</name>
|
||||
<description>tutorial for spring-data-cosmosdb</description>
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-cosmosdb</artifactId>
|
||||
<name>spring-data-cosmos-db</name>
|
||||
<description>tutorial for spring-data-cosmosdb</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<cosmodb.version>2.3.0</cosmodb.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>spring-data-cosmosdb</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>spring-data-cosmosdb</artifactId>
|
||||
<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>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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