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); }
新增好友功展示
通過搜尋好友姓名新增好友
通過掃描二維碼新增好友