Commit 18137b5a authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-58] Work on DEL product endpoint

parent d6474c5a
...@@ -16,7 +16,7 @@ public class ProductController { ...@@ -16,7 +16,7 @@ public class ProductController {
@DeleteMapping(value = "/{sku}") @DeleteMapping(value = "/{sku}")
public void deleteProduct(@PathVariable String sku) { public void deleteProduct(@PathVariable String sku) {
// productService.removeProductBySku(sku).subscribe(); productService.removeProductBySku(sku).subscribe();
} }
} }
...@@ -10,6 +10,4 @@ import reactor.core.publisher.Mono; ...@@ -10,6 +10,4 @@ import reactor.core.publisher.Mono;
public interface ProductRepository extends ReactiveMongoRepository<Product, String> { public interface ProductRepository extends ReactiveMongoRepository<Product, String> {
Mono<Product> findBySku(String sku); Mono<Product> findBySku(String sku);
Mono<ProductDto> deleteProduct(ProductDto prod);
} }
...@@ -17,13 +17,12 @@ public class ProductService { ...@@ -17,13 +17,12 @@ public class ProductService {
@Autowired @Autowired
ProductRepository productRepository; ProductRepository productRepository;
public Mono<ProductDto> removeProductBySku(String sku){ public Mono<Product> removeProductBySku(String sku){
return productRepository return productRepository
.findBySku(sku) .findBySku(sku)
.map(ProductDto::generateDtoFromProduct) .flatMap(existingProduct -> productRepository.delete(existingProduct)
.flatMap(existingProduct -> productRepository.deleteProduct(existingProduct)
.then(Mono.just(existingProduct))) .then(Mono.just(existingProduct)))
.switchIfEmpty(Mono.error(new ResourceNotFoundException(HttpStatus.NOT_FOUND, "product not found"))); .switchIfEmpty(Mono.error(new ResourceNotFoundException(HttpStatus.NOT_FOUND, "Product Not Found")));
} }
} }
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