|
|
@@ -3,6 +3,9 @@ package com.seecoder.BlueWhale.serviceImpl;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.seecoder.BlueWhale.po.StoreStar;
|
|
|
+import com.seecoder.BlueWhale.repository.StoreStarRepository;
|
|
|
+import com.seecoder.BlueWhale.util.SecurityUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -18,6 +21,12 @@ public class StoreServiceImpl implements StoreService {
|
|
|
@Autowired
|
|
|
StoreRepository storeRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SecurityUtil securityUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StoreStarRepository storeStarRepository;
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean create(StoreVO storeVO) {
|
|
|
Store store = storeRepository.findByName(storeVO.getName());
|
|
|
@@ -44,5 +53,26 @@ public class StoreServiceImpl implements StoreService {
|
|
|
public List<StoreVO> getAllStores() {
|
|
|
return storeRepository.findAll().stream().map(Store::toVO).collect(Collectors.toList());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean starStores(Integer storeId, Integer rate) {
|
|
|
+ int userId=securityUtil.getCurrentUser().getId();
|
|
|
+ if (storeStarRepository.findByUserIdAndStoreId(userId,storeId)!=null){
|
|
|
+ throw BlueWhaleException.starAlreadyExists();
|
|
|
+ }
|
|
|
+ StoreStar storeStar=new StoreStar();
|
|
|
+ storeStar.setRate(rate);
|
|
|
+ storeStar.setStoreId(storeId);
|
|
|
+ storeStar.setUserId(userId);
|
|
|
+ storeStarRepository.save(storeStar);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getStoreStar(Integer storeId) {
|
|
|
+ int userId=securityUtil.getCurrentUser().getId();
|
|
|
+ StoreStar storeStar=storeStarRepository.findByUserIdAndStoreId(userId,storeId);
|
|
|
+ return storeStar==null?0:storeStar.getRate();
|
|
|
+ }
|
|
|
+
|
|
|
}
|