目录
1:交友项目
1.1:查询黑名单人员
1.1.1:接口地址
1.1.2:流程分析
1.1.2:代码实现
1.2:移除黑名单人员
1.2.1:接口地址
1.2.2:流程分析
1.2.3:代码实现
1:交友项目
1.1:查询黑名单人员
1.1.1:接口地址
接口地址:http://192.168.136.160:3000/project/19/interface/api/286
1.1.2:流程分析
展示:如图信息
通过id到黑名单表中查询所对应的黑名单中人员信息,并分页,封装返回前端
1.1.2:代码实现
与前端交互的app-server模块
controller层实现
@GetMapping("/blacklist")
public ResponseEntity findblacklist(BlackListVo blackListVo){
System.out.println(blackListVo);
ResultList findblacklist = userService.findblacklist(blackListVo,UserHolder.getUserId());
return ResponseEntity.ok(findblacklist);
}
service层实现
public ResultList findblacklist(BlackListVo blackListVo, Long userId) {
ResultList findblacklist = userApi.findblacklist(blackListVo,userId);
return findblacklist;
}
统一封装接口的模块
ResultList findblacklist(BlackListVo blackListVo, Long userId);
提供者模块(提供相关接口的实现)
@Override
public ResultList findblacklist(BlackListVo blackListVo, Long userId) {
QueryWrapper<BlackList> blackListQueryWrapper = new QueryWrapper<>();
blackListQueryWrapper.eq("user_id",userId);
Page<BlackList> blackListPage = new Page<>(blackListVo.getPage(), blackListVo.getPagesize());
Page<BlackList> blackListPage1 = blackMapper.selectPage(blackListPage, blackListQueryWrapper);
// //处理起始的索引
// List<BlackList> allBlack = blackMapper.findAllBlack(blackListVo.getPage() - 1, blackListVo.getPagesize());
ResultList resultList = new ResultList();
//设置页大小
resultList.setPagesize(Math.toIntExact(blackListPage1.getSize()));
//设置总记录数
resultList.setCounts(Math.toIntExact(blackListPage1.getTotal()));
//处理当前页
resultList.setPage(Math.toIntExact(blackListPage1.getCurrent()));
//处理总页数
resultList.setPages(Math.toIntExact(blackListPage1.getPages()));
for (BlackList record : blackListPage1.getRecords()) {
UserInfo userInfo = userInfoMapper.selectById(record.getBlackUserId());
if (userInfo != null){
record.setAvatar(userInfo.getAvatar());
record.setNickname(userInfo.getNickname());
record.setGender(userInfo.getGender());
record.setAge(userInfo.getAge());
}
}
resultList.setItems(blackListPage1.getRecords().toArray());
return resultList;
}
1.2:移除黑名单人员
1.2.1:接口地址
接口地址:http://192.168.136.160:3000/project/19/interface/api/283
1.2.2:流程分析
将数据库中对应的黑名单表通过前端传递的id值,进行移除响应的表数据。
1.2.3:代码实现
与前端交互的app-server模块
controller层实现
/**
* 移除黑名单
*/
@DeleteMapping("/blacklist/{uid}")
public ResponseEntity deleteblack(@PathVariable("uid") Long uid){
userService.deleteblack(uid);
return ResponseEntity.ok(null);
}
service层实现
public void deleteblack(Long uid) {
userApi.deleteblack(uid);
}
统一封装接口的模块
void deleteblack(Long uid);
提供者模块(提供相关接口的实现)
@Override
public void deleteblack(Long uid) {
blackMapper.deleteById(uid);
}