Browse Source

feat:修复了获得收藏交流的bug

DingXiaoYu 3 năm trước cách đây
mục cha
commit
836eb490e3

+ 0 - 2
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/repository/CommunicationRepository.java

@@ -16,6 +16,4 @@ public interface CommunicationRepository extends JpaRepository<Communication,Lon
 
     Page<Communication> findByPublisherId(Long publisherId,Pageable pageable);
 
-    @Select("select * from communication A where exist (select * from communication_star B where A.id=B.communicationId and B.userId=${userId})")
-    Page<Communication> findByStarUserId(Long userId, Pageable pageable);
 }

+ 4 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/repository/CommunicationStarRepository.java

@@ -1,6 +1,8 @@
 package cn.seecoder.seecoderportalserver.repository;
 
 import cn.seecoder.seecoderportalserver.domain.CommunicationStar;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 
 import java.util.List;
@@ -18,4 +20,6 @@ public interface CommunicationStarRepository extends JpaRepository<Communication
     void deleteByUserIdAndCommunicationId(Long userId,Long communicationId);
 
     List<CommunicationStar> findByCommunicationId(Long communicationId);
+
+    Page<CommunicationStar> findByUserId(Long userId, Pageable pageable);
 }

+ 5 - 5
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/CommunicationServiceImpl.java

@@ -16,10 +16,7 @@ import cn.seecoder.seecoderportalserver.service.CommunicationService;
 import cn.seecoder.seecoderportalserver.service.UserService;
 import cn.seecoder.seecoderportalserver.utility.OssUtil;
 import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
@@ -193,7 +190,10 @@ public class CommunicationServiceImpl implements CommunicationService {
     @Override
     public PageVO<CommunicationVO> getStarredCommunicationPage(Long userId, Integer page, Integer size) {
         Pageable pageable = PageRequest.of(page,size);
-        Page<Communication> communications=communicationRepository.findByStarUserId(userId,pageable);
+        Page<CommunicationStar> communicationStars=communicationStarRepository.findByUserId(userId,pageable);
+        Page<Communication> communications=new PageImpl<>(communicationStars.getContent().stream().map(
+                communicationStar -> communicationRepository.findById(communicationStar.getCommunicationId()).get()
+        ).collect(Collectors.toList()),pageable,communicationStars.getTotalElements());
         return toPageVO(communications,userId);
     }