use of com.wooyoo.learning.dao.domain.Product in project spring-boot-mybatis-with-redis by Lovelcp.
the class SpringBootMybatisWithRedisApplicationTests method test.
@Test
public void test() {
long productId = 1;
Product product = restTemplate.getForObject("http://localhost:" + port + "/product/" + productId, Product.class);
assertThat(product.getPrice()).isEqualTo(200);
Product newProduct = new Product();
long newPrice = new Random().nextLong();
newProduct.setName("new name");
newProduct.setPrice(newPrice);
restTemplate.put("http://localhost:" + port + "/product/" + productId, newProduct);
Product testProduct = restTemplate.getForObject("http://localhost:" + port + "/product/" + productId, Product.class);
assertThat(testProduct.getPrice()).isEqualTo(newPrice);
}
use of com.wooyoo.learning.dao.domain.Product in project spring-boot-mybatis-with-redis by Lovelcp.
the class ProductController method updateProductInfo.
@PutMapping("/{id}")
public Product updateProductInfo(@PathVariable("id") Long productId, @RequestBody Product newProduct) {
Product product = productMapper.select(productId);
if (product == null) {
throw new ProductNotFoundException(productId);
}
product.setName(newProduct.getName());
product.setPrice(newProduct.getPrice());
productMapper.update(product);
return product;
}
Aggregations