|
|
@@ -1,9 +1,16 @@
|
|
|
package com.seecoder.BlueWhale.ServiceImpl;
|
|
|
|
|
|
import com.seecoder.BlueWhale.Repository.ProductRepository;
|
|
|
+import com.seecoder.BlueWhale.Repository.StoreRepository;
|
|
|
+import com.seecoder.BlueWhale.Exception.BlueWhaleException;
|
|
|
import com.seecoder.BlueWhale.PO.Product;
|
|
|
+import com.seecoder.BlueWhale.PO.Store;
|
|
|
import com.seecoder.BlueWhale.Service.ProductService;
|
|
|
import com.seecoder.BlueWhale.VO.ProductVO;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -13,6 +20,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
ProductRepository productRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ StoreRepository storeRepository;
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean create(ProductVO productVO) {
|
|
|
Product product=productVO.toPO();
|
|
|
@@ -23,4 +33,24 @@ public class ProductServiceImpl implements ProductService {
|
|
|
productRepository.save(product);
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean addStock(Integer id) {
|
|
|
+ Product product=productRepository.findById(id).orElse(null);
|
|
|
+ if(product==null){
|
|
|
+ throw BlueWhaleException.productNotExists();
|
|
|
+ }
|
|
|
+ product.setStock(product.getStock()+1);
|
|
|
+ productRepository.save(product);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ProductVO> getAllProducts(Integer storeId) {
|
|
|
+ Store store = storeRepository.findById(storeId).orElse(null);
|
|
|
+ if (store == null) {
|
|
|
+ throw BlueWhaleException.storeNotExists();
|
|
|
+ }
|
|
|
+ return productRepository.findAllByStoreId(storeId).stream().map(Product::toVO).collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|