Ver código fonte

关注我的,我收藏的

xiongzhu 4 anos atrás
pai
commit
0390e0fc91

+ 4 - 0
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
+import java.util.List;
 import java.util.Optional;
 
 public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
@@ -22,4 +23,7 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
     @Transactional
     void addLike(Long id, int num);
 
+    @Query(value = "select distinct c from Collection c join Like l on l.collectionId = c.id " +
+            "where l.userId = ?1 and l.del = false and c.del = false")
+    List<Collection> userLikes(Long userId);
 }

+ 4 - 0
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -36,6 +36,10 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
             "where f.userId = ?1 and u.del = false ")
     List<User> userFollows(Long userId);
 
+    @Query("select distinct u from User u join Follow f on u.id = f.userId " +
+            "where f.followUserId = ?1 and u.del = false ")
+    List<User> userFollowers(Long userId);
+
     @Transactional
     @Modifying
     @Query(value = "update user set follows = (select count(*) from follow " +

+ 6 - 0
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -73,5 +73,11 @@ public class CollectionController extends BaseController {
     public void unlike(@PathVariable Long id) {
         likeService.unlike(SecurityUtils.getAuthenticatedUser().getId(), id);
     }
+
+    @GetMapping("/myLikes")
+    @ApiOperation("我收藏的")
+    public List<CollectionDTO> myLikes( ) {
+       return  collectionService.toDTO(collectionRepo.userLikes(SecurityUtils.getAuthenticatedUser().getId()));
+    }
 }
 

+ 6 - 0
src/main/java/com/izouma/nineth/web/UserController.java

@@ -154,6 +154,12 @@ public class UserController extends BaseController {
     public List<UserDTO> myFollows() {
         return userService.toDTO(userRepo.userFollows(SecurityUtils.getAuthenticatedUser().getId()));
     }
+
+    @GetMapping("/myFollowers")
+    @ApiOperation("关注我的")
+    public List<UserDTO> myFollowers() {
+        return userService.toDTO(userRepo.userFollowers(SecurityUtils.getAuthenticatedUser().getId()));
+    }
 }