Commit e8e02a98 authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-57] Start work on UPDATE product endpoint

parent 52107bd4
......@@ -32,4 +32,13 @@ public class ProductController {
public ResponseEntity<Flux<ProductDto>> getAllProducts() {
return ResponseEntity.ok(productService.findAllProducts());
}
// @PutMapping("/{userId}")
// public Mono<ResponseEntity<Product>> updateProduct(@PathVariable String sku, @RequestBody Product product){
// return productService.updateProductBySku(sku,user)
// .map(updatedProduct -> ResponseEntity.ok(updatedProduct))
// .defaultIfEmpty(ResponseEntity.badRequest().build());
// }
}
......@@ -28,5 +28,21 @@ public class ProductService {
.map(ProductDto::generateDtoFromProduct);
}
public Mono<Product> updateProduct(String sku, Product product){
return productRepository.findById(sku)
.flatMap(dbProduct -> {
dbProduct.setUpc(product.getUpc());
dbProduct.setProductName(product.getProductName());
dbProduct.setProductDescription(product.getProductDescription());
dbProduct.setPrice(product.getPrice());
dbProduct.setAvailableStock(product.getAvailableStock());
dbProduct.setBlockedStock(product.getBlockedStock());
dbProduct.setProductImageUrl(product.getProductImageUrl());
dbProduct.setBrand(product.getBrand());
dbProduct.setCategory(product.getCategory());
return productRepository.save(dbProduct);
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment