easylive项目学习---个人中心

1.获取用户信息

参数:

public ResponseVO getUserInfo(@NotEmpty String userId)

具体实现非常简单不再赘述

2.更新用户信息

public ResponseVO updateUserInfo(@NotEmpty @Size(max=20)String nickName,
                                 @NotEmpty @Size(max=20) String avatar,
                                 @NotNull Integer sex,
                                 @Size(max=10) String birthday,
                                 @Size(max=150) String school,
                                 @Size(max=80) String personIntroduction,
                                 @Size(max=300) String noticeInfo)

不使用实体类传递信息是因为担心被恶意传递参数(因为实体类里面有不需要的多余的内容) 而且不方便用aop进行参数校验与限制 

更新用户信息有两步:1.更新数据库中用户的信息 十分简单不再赘述

2.第二部缓存中用户信息 便于接下来的参数查询(否则你在此接口修改信息后 redis中的信息依旧是旧信息 再后面的接口访问时候调用redis就会发生参数不一致的现象)

更新redis:
 

public void updateTokenInfo(TokenUserInfoDto tokenUserInfoDto){
    redisUtils.setex(Constants.REDIS_KEY_TOKEN_WEB+tokenUserInfoDto.getToken(),tokenUserInfoDto,Constants.REDIS_KEY_EXPIRES_DAY*7);
}

3.关注与粉丝
表结构:

有两种构建表的方法:第一种就是双表 一张表为关注表 一张为粉丝表 便于理解但是会降低数据库效率 因为双表就代表着要查询两次 修改两次表 第二种如图所示 单表 虽然还是需要查询两次 但修改只需要一次 提高了数据库效率

关注参数:

public ResponseVO focus(@NotEmpty String focusUserId)

关注的实现类注意点:验证身份 不可以自己关注自己 关注的人是否存在(避免恶意传参数导致数据库崩溃)

实现代码:

public void focusUser(String userId, String focusUserId) {
   if (userId.equals(focusUserId)){
      throw new BusinessException("不可以关注自己");
   }
   UserFocus dbInfo=this.userFocusMapper.selectByUserIdAndFocusUserId(userId,focusUserId);
   if (dbInfo!=null){
      return;
   }
   UserInfo userInfo=userInfoMapper.selectByUserId(focusUserId);
   if (userInfo==null){
      throw new BusinessException(ResponseCodeEnum.CODE_600);
   }
   UserFocus focus=new UserFocus();
   focus.setUserId(userId);
   focus.setFocusUserId(focusUserId);
   focus.setFocusTime(new Date());
   this.userFocusMapper.insert(focus);
}

取消关注:
参数:

public ResponseVO cancelFocus(@NotEmpty String focusUserId)

取消关注实现层非常简单 仅仅将表记录删除即可

展示关注列表:

参数:
 

public ResponseVO loadFocusList(Integer pageNo)

自己写分页查询在上一篇easylive项目学习中有 不再赘述  也可以使用pageHelper查找

展示粉丝列表:

同上

4.视频列表与收藏列表:
代码实现:
 

@RequestMapping("/loadVideoList")
public ResponseVO loadVideoList(@NotEmpty String userId,Integer type,Integer pageNo,String videoName,Integer orderType){
    VideoInfoQuery infoQuery=new VideoInfoQuery();
    if (type!=null){
        infoQuery.setPageSize(PageSize.SIZE10.getSize());
    }
    VideoOrderTypeEnum videoOrderTypeEnum=VideoOrderTypeEnum.getByType(orderType);
    if (videoOrderTypeEnum==null){
        videoOrderTypeEnum=VideoOrderTypeEnum.CREATE_TIME;
    }
    infoQuery.setOrderBy(videoOrderTypeEnum.getField()+"desc");
    infoQuery.setVideoNameFuzzy(videoName);
    infoQuery.setPageNo(pageNo);
    infoQuery.setUserId(userId);
    PaginationResultVO resultVO=videoInfoService.findListByPage(infoQuery);
    return getSuccessResponseVO(resultVO);
}

@RequestMapping("/loadUserCollection")
public ResponseVO loadUserCollection(@NotEmpty String userId,Integer pageNo){
    UserActionQuery actionQuery=new UserActionQuery();
    actionQuery.setActionType(UserActionTypeEnum.VIDEO_COLLECT.getType());
    actionQuery.setUserId(userId);
    actionQuery.setPageNo(pageNo);
    actionQuery.setOrderBy("action_time desc");
    actionQuery.setQueryVideoInfo(true);
    PaginationResultVO resultVO=userActionService.findListByPage(actionQuery);
    return getSuccessResponseVO(resultVO);
}

非常简单无需赘述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值