@@ -29,4 +29,9 @@ public class ProductController {
public ResultVO<List<ProductVO>> getAllProducts(@RequestParam("storeId") Integer storeId){
return ResultVO.buildSuccess(productService.getAllProducts(storeId));
}
+
+ @GetMapping("/{id}")
+ public ResultVO<ProductVO> getProduct(@PathVariable(value = "id") Integer id){
+ return ResultVO.buildSuccess(productService.getProduct(id));
+ }
@@ -8,4 +8,5 @@ public interface ProductService {
Boolean create(ProductVO productVO);
Boolean addStock(Integer id, Integer number);
List<ProductVO> getAllProducts(Integer storeId);
+ ProductVO getProduct(Integer id);
@@ -56,4 +56,13 @@ public class ProductServiceImpl implements ProductService {
return productRepository.findAllByStoreId(storeId).stream().map(Product::toVO).collect(Collectors.toList());
+ @Override
+ public ProductVO getProduct(Integer id) {
+ Product product=productRepository.findById(id).orElse(null);
+ if(product==null){
+ throw BlueWhaleException.productNotExists();
+ return product.toVO();