Commit 719e63af authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-58] Start work on delete endpoint

parent 892ead98
package com.nisum.ascend.inventory.controller; package com.nisum.ascend.inventory.controller;
import com.nisum.ascend.inventory.dto.ProductDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.nisum.ascend.inventory.service.ProductService; import com.nisum.ascend.inventory.service.ProductService;
import reactor.core.publisher.Mono;
@RestController @RestController
@RequestMapping("/api/products")
public class ProductController { public class ProductController {
@Autowired @Autowired
ProductService productService; ProductService productService;
@DeleteMapping(value = "/{sku}")
public void deleteProduct(@PathVariable String sku) {
productService.removeProductBySku(sku).subscribe();
}
} }
...@@ -5,10 +5,15 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -5,10 +5,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import com.nisum.ascend.inventory.repository.ProductRepository; import com.nisum.ascend.inventory.repository.ProductRepository;
import reactor.core.publisher.Mono;
@Service @Service
public class ProductService { public class ProductService {
@Autowired @Autowired
ProductRepository productRepository; ProductRepository productRepository;
public Mono<Void> removeProductBySku(String sku){
return productRepository.deleteById(sku);
}
} }
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