内容简介:Netty+SpringBoot+FastDFS+Html5实现聊天App,项目介绍。Netty+SpringBoot+FastDFS+Html5实现聊天App,
Netty+SpringBoot+FastDFS+Html5实现聊天App,项目介绍。
Netty+SpringBoot+FastDFS+Html5实现聊天App, 项目github链接 。
本章完整代码链接 。
本章内容
(1) 查询好友列表的接口
(2)通过或忽略好友请求的接口
(3)添加好友功能展示
查询好友列表的接口
/**
* @Description: 查询我的好友列表
*/
@PostMapping("/myFriends")
public IMoocJSONResult myFriends(String userId) {
// 0. userId 判断不能为空
if (StringUtils.isBlank(userId)) {
return IMoocJSONResult.errorMsg("");
}
// 1. 数据库查询好友列表
List<MyFriendsVO> myFirends = userService.queryMyFriends(userId);
return IMoocJSONResult.ok(myFirends);
}
通过或忽略好友请求的接口
定义枚举类型
/**
*
* @Description: 忽略或者通过 好友请求的枚举
*/
public enum OperatorFriendRequestTypeEnum {
IGNORE(0, "忽略"),
PASS(1, "通过");
public final Integer type;
public final String msg;
OperatorFriendRequestTypeEnum(Integer type, String msg){
this.type = type;
this.msg = msg;
}
public Integer getType() {
return type;
}
public static String getMsgByType(Integer type) {
for (OperatorFriendRequestTypeEnum operType : OperatorFriendRequestTypeEnum.values()) {
if (operType.getType() == type) {
return operType.msg;
}
}
return null;
}
}
controller中提供通过或忽略好友请求的接口
/**
* @Description: 接受方 通过或者忽略朋友请求
*/
@PostMapping("/operFriendRequest")
public IMoocJSONResult operFriendRequest(String acceptUserId, String sendUserId,
Integer operType) {
// 0. acceptUserId sendUserId operType 判断不能为空
if (StringUtils.isBlank(acceptUserId)
|| StringUtils.isBlank(sendUserId)
|| operType == null) {
return IMoocJSONResult.errorMsg("");
}
// 1. 如果operType 没有对应的枚举值,则直接抛出空错误信息
if (StringUtils.isBlank(OperatorFriendRequestTypeEnum.getMsgByType(operType))) {
return IMoocJSONResult.errorMsg("");
}
if (operType == OperatorFriendRequestTypeEnum.IGNORE.type) {
// 2. 判断如果忽略好友请求,则直接删除好友请求的数据库表记录
userService.deleteFriendRequest(sendUserId, acceptUserId);
} else if (operType == OperatorFriendRequestTypeEnum.PASS.type) {
// 3. 判断如果是通过好友请求,则互相增加好友记录到数据库对应的表
// 然后删除好友请求的数据库表记录
userService.passFriendRequest(sendUserId, acceptUserId);
}
// 4. 数据库查询好友列表
List<MyFriendsVO> myFirends = userService.queryMyFriends(acceptUserId);
// 5. 将查询到的好友列表返回给前端
return IMoocJSONResult.ok(myFirends);
}
添加好友功展示
通过搜索好友姓名添加好友
通过扫描二维码添加好友
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Redis开发与运维
付磊、张益军 / 机械工业出版社 / 2017-3-1 / 89.00
本书全面讲解Redis基本功能及其应用,并结合线上开发与运维监控中的实际使用案例,深入分析并总结了实际开发运维中遇到的“陷阱”,以及背后的原因, 包含大规模集群开发与管理的场景、应用案例与开发技巧,为高效开发运维提供了大量实际经验和建议。本书不要求读者有任何Redis使用经验,对入门与进阶DevOps的开发者提供有价值的帮助。主要内容包括:Redis的安装配置、API、各种高效功能、客户端、持久化......一起来看看 《Redis开发与运维》 这本书的介绍吧!