diff --git a/src/main/java/com/rymcu/vertical/mapper/FollowMapper.java b/src/main/java/com/rymcu/vertical/mapper/FollowMapper.java index 09e1105..ec1e638 100644 --- a/src/main/java/com/rymcu/vertical/mapper/FollowMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/FollowMapper.java @@ -1,9 +1,12 @@ package com.rymcu.vertical.mapper; import com.rymcu.vertical.core.mapper.Mapper; +import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Follow; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * @author ronger */ @@ -16,4 +19,18 @@ public interface FollowMapper extends Mapper { * @return */ Boolean isFollow(@Param("followingId") Integer followingId, @Param("followerId") Integer followerId, @Param("followingType") String followingType); + + /** + * 查询用户粉丝 + * @param idUser + * @return + */ + List selectUserFollowersByUser(@Param("idUser") Integer idUser); + + /** + * 查询用户关注用户 + * @param idUser + * @return + */ + List selectUserFollowingsByUser(@Param("idUser") Integer idUser); } diff --git a/src/main/java/com/rymcu/vertical/service/FollowService.java b/src/main/java/com/rymcu/vertical/service/FollowService.java index 37f2dba..1745702 100644 --- a/src/main/java/com/rymcu/vertical/service/FollowService.java +++ b/src/main/java/com/rymcu/vertical/service/FollowService.java @@ -1,6 +1,7 @@ package com.rymcu.vertical.service; import com.rymcu.vertical.core.service.Service; +import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Follow; import com.rymcu.vertical.web.api.exception.BaseApiException; @@ -42,4 +43,20 @@ public interface FollowService extends Service { * @return */ List findByFollowingId(String followType, Integer followingId); + + + + /** + * 查询用户粉丝 + * @param userDTO + * @return + */ + List findUserFollowersByUser(UserDTO userDTO); + + /** + * 查询用户关注用户 + * @param userDTO + * @return + */ + List findUserFollowingsByUser(UserDTO userDTO); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java index 1356a15..a603d0b 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/FollowServiceImpl.java @@ -2,6 +2,7 @@ package com.rymcu.vertical.service.impl; import com.rymcu.vertical.core.constant.NotificationConstant; import com.rymcu.vertical.core.service.AbstractService; +import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Follow; import com.rymcu.vertical.entity.User; import com.rymcu.vertical.mapper.FollowMapper; @@ -56,4 +57,16 @@ public class FollowServiceImpl extends AbstractService implements Follow follow.setFollowingId(followingId); return followMapper.select(follow); } + + @Override + public List findUserFollowersByUser(UserDTO userDTO) { + List list = followMapper.selectUserFollowersByUser(userDTO.getIdUser()); + return list; + } + + @Override + public List findUserFollowingsByUser(UserDTO userDTO) { + List list = followMapper.selectUserFollowingsByUser(userDTO.getIdUser()); + return list; + } } diff --git a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java index ba2f040..a8ecea8 100644 --- a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java +++ b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java @@ -9,6 +9,7 @@ import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.dto.PortfolioDTO; import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.service.ArticleService; +import com.rymcu.vertical.service.FollowService; import com.rymcu.vertical.service.PortfolioService; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.Utils; @@ -32,6 +33,8 @@ public class UserController { private ArticleService articleService; @Resource private PortfolioService portfolioService; + @Resource + private FollowService followService; @GetMapping("/{nickname}") @VisitLogger @@ -69,4 +72,36 @@ public class UserController { return GlobalResultGenerator.genSuccessResult(map); } + @GetMapping("/{nickname}/followers") + public GlobalResult userFollowers(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){ + UserDTO userDTO = userService.findUserDTOByNickname(nickname); + if (userDTO == null){ + return GlobalResultGenerator.genErrorResult("用户不存在!"); + } + PageHelper.startPage(page, rows); + List list = followService.findUserFollowersByUser(userDTO); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(2); + map.put("users", list); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + @GetMapping("/{nickname}/followings") + public GlobalResult userFollowings(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){ + UserDTO userDTO = userService.findUserDTOByNickname(nickname); + if (userDTO == null){ + return GlobalResultGenerator.genErrorResult("用户不存在!"); + } + PageHelper.startPage(page, rows); + List list = followService.findUserFollowingsByUser(userDTO); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(2); + map.put("users", list); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 6a45224..b0fe802 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -138,6 +138,6 @@ select exists (select * from vertical_comment where comment_article_id = #{id}) \ No newline at end of file