From 10941376f122d498299ca21b1b2841092ae379e6 Mon Sep 17 00:00:00 2001 From: zhaocy Date: Thu, 16 Jun 2022 15:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9errcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api_addblack.go | 4 ++-- modules/friend/api_agree.go | 13 ++++++++----- modules/friend/api_apply.go | 7 +++---- modules/friend/api_applylist.go | 9 ++++----- modules/friend/api_blacklist.go | 9 ++++----- modules/friend/api_delblack.go | 15 +++++++++------ modules/friend/api_list.go | 9 ++++----- modules/friend/api_refuse.go | 13 ++++++++----- modules/friend/api_search.go | 7 +++---- modules/user/api_create.go | 10 +++++----- modules/user/api_login.go | 10 +++++----- 11 files changed, 55 insertions(+), 51 deletions(-) diff --git a/modules/friend/api_addblack.go b/modules/friend/api_addblack.go index 5454f0615..6533866a8 100644 --- a/modules/friend/api_addblack.go +++ b/modules/friend/api_addblack.go @@ -27,7 +27,7 @@ func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interfac UserId: session.GetUserId(), } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, rsp) }() err = this.module.model_friend.GetObj(session.GetUserId(), self) @@ -65,5 +65,5 @@ func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interfac //更新黑名单 this.module.model_friend.SetObj(self.UserId, self, false, true) - return nil + return } diff --git a/modules/friend/api_agree.go b/modules/friend/api_agree.go index 21bffd1e9..bc8a13ffc 100644 --- a/modules/friend/api_agree.go +++ b/modules/friend/api_agree.go @@ -34,9 +34,8 @@ func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.FriendAgreeR } //单个/批量同意 -func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendAgreeReq) (err error) { +func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendAgreeReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode self *pb.DB_FriendData rsp *pb.FriendAgreeRsp optNum int32 @@ -48,7 +47,7 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{} Num: optNum, } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_Agree, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_Agree, rsp) }() if v, ok := chk["self"]; !ok { @@ -92,8 +91,12 @@ func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{} } //更新 - return this.module.model_friend.SetObj(self.UserId, self, false, true) + err := this.module.model_friend.SetObj(self.UserId, self, false, true) + if err != nil { + code = pb.ErrorCode_DBError + return + } } - return nil + return } diff --git a/modules/friend/api_apply.go b/modules/friend/api_apply.go index 87ff5678e..82eff4a4f 100644 --- a/modules/friend/api_apply.go +++ b/modules/friend/api_apply.go @@ -79,9 +79,8 @@ func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyR } //好友申请 -func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyReq) (err error) { +func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode target *pb.DB_FriendData rsp *pb.FriendApplyRsp ) @@ -97,7 +96,7 @@ func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{} FriendId: req.FriendId, } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_Apply, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_Apply, rsp) }() if v, ok := chk["target"]; !ok { @@ -113,7 +112,7 @@ func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{} } target.ApplyIds = append(target.ApplyIds, session.GetUserId()) - err = this.module.model_friend.SetObj(req.FriendId, target, false, true) + err := this.module.model_friend.SetObj(req.FriendId, target, false, true) if err != nil { log.Errorf("firend Apply err:%v", err) diff --git a/modules/friend/api_applylist.go b/modules/friend/api_applylist.go index 79e524993..8907c1caa 100644 --- a/modules/friend/api_applylist.go +++ b/modules/friend/api_applylist.go @@ -10,9 +10,8 @@ func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.FriendAp } //申请列表 -func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyListReq) (err error) { +func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyListReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode self *pb.DB_FriendData rsp *pb.FriendApplyListRsp list []*pb.FriendBase @@ -24,10 +23,10 @@ func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interfa List: list, } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_ApplyList, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_ApplyList, rsp) }() - err = this.module.model_friend.GetObj(session.GetUserId(), self) + err := this.module.model_friend.GetObj(session.GetUserId(), self) if self == nil || err != nil { code = pb.ErrorCode_FriendSelfNoData return @@ -40,5 +39,5 @@ func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interfa }) } - return nil + return } diff --git a/modules/friend/api_blacklist.go b/modules/friend/api_blacklist.go index af66da77f..c0615070e 100644 --- a/modules/friend/api_blacklist.go +++ b/modules/friend/api_blacklist.go @@ -10,9 +10,8 @@ func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.FriendBl } //黑名单 -func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackListReq) (err error) { +func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackListReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode self *pb.DB_FriendData rsp *pb.FriendBlackListRsp list []*pb.FriendBase @@ -24,10 +23,10 @@ func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interfa Friends: list, } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_Blacklist, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_Blacklist, rsp) }() - err = this.module.model_friend.GetObj(session.GetUserId(), self) + err := this.module.model_friend.GetObj(session.GetUserId(), self) if self == nil || err != nil { code = pb.ErrorCode_FriendSelfNoData return @@ -40,5 +39,5 @@ func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interfa }) } - return nil + return } diff --git a/modules/friend/api_delblack.go b/modules/friend/api_delblack.go index 2e8dea605..4ad3daf9d 100644 --- a/modules/friend/api_delblack.go +++ b/modules/friend/api_delblack.go @@ -11,9 +11,8 @@ func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.FriendDel } //删除黑名单 -func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelBlackReq) (err error) { +func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelBlackReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode self *pb.DB_FriendData rsp *pb.FriendDelBlackRsp ) @@ -24,9 +23,9 @@ func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interfac UserId: session.GetUserId(), } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, rsp) }() - err = this.module.model_friend.GetObj(session.GetUserId(), self) + err := this.module.model_friend.GetObj(session.GetUserId(), self) if self == nil || err != nil { code = pb.ErrorCode_FriendSelfNoData return @@ -35,6 +34,10 @@ func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interfac //从黑名单列表中删除目标 self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId) //更新黑名单 - return this.module.model_friend.SetObj(self.UserId, self, false, true) - + err = this.module.model_friend.SetObj(self.UserId, self, false, true) + if err != nil { + code = pb.ErrorCode_DBError + return + } + return } diff --git a/modules/friend/api_list.go b/modules/friend/api_list.go index 9d4bfc0b9..b49abe1a6 100644 --- a/modules/friend/api_list.go +++ b/modules/friend/api_list.go @@ -10,9 +10,8 @@ func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.FriendListReq } //好友列表 -func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendListReq) (err error) { +func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendListReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode self *pb.DB_FriendData rsp *pb.FriendListRsp list []*pb.FriendBase @@ -24,10 +23,10 @@ func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, List: list, } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_List, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_List, rsp) }() - err = this.module.model_friend.GetObj(session.GetUserId(), self) + err := this.module.model_friend.GetObj(session.GetUserId(), self) if self == nil || err != nil { code = pb.ErrorCode_FriendSelfNoData return @@ -39,5 +38,5 @@ func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, }) } - return nil + return } diff --git a/modules/friend/api_refuse.go b/modules/friend/api_refuse.go index f139d68ba..feacf9506 100644 --- a/modules/friend/api_refuse.go +++ b/modules/friend/api_refuse.go @@ -33,10 +33,9 @@ func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.FriendRefus } //单个/批量拒绝 -func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendRefuseReq) (err error) { +func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendRefuseReq) (code pb.ErrorCode) { //将申请人从申请列表中删除 var ( - code pb.ErrorCode self *pb.DB_FriendData rsp *pb.FriendAgreeRsp optNum int32 @@ -47,7 +46,7 @@ func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{ Num: optNum, } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_Refuse, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_Refuse, rsp) }() if v, ok := chk["self"]; !ok { @@ -64,10 +63,14 @@ func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{ } //更新 if optNum > 0 { - return this.module.model_friend.SetObj(self.UserId, self, false, true) + err := this.module.model_friend.SetObj(self.UserId, self, false, true) + if err != nil { + code = pb.ErrorCode_DBError + return + } } } } - return nil + return } diff --git a/modules/friend/api_search.go b/modules/friend/api_search.go index e20a1dadf..1d554801d 100644 --- a/modules/friend/api_search.go +++ b/modules/friend/api_search.go @@ -10,9 +10,8 @@ func (this *ApiComp) Search_Check(session comm.IUserSession, req *pb.FriendSearc } //搜索 -func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendSearchReq) error { +func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendSearchReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode rsp *pb.FriendSearchRsp friend *pb.FriendBase ) @@ -22,7 +21,7 @@ func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{ Friend: friend, } } - session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, code, rsp) + session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, rsp) }() user := this.module.model_friend.Frined_FindCond(req.NickName) @@ -32,5 +31,5 @@ func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{ NickName: user.Name, } } - return nil + return } diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 6f3b66bce..a40863732 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -12,20 +12,20 @@ func (this *Api_Comp) Create_Check(session comm.IUserSession, req *pb.UserCreate } //创角 -func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interface{}, req *pb.UserCreateReq) (err error) { +func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interface{}, req *pb.UserCreateReq) (code pb.ErrorCode) { defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), User_SubType_Create, req, nil) - var code pb.ErrorCode + self := &pb.DB_UserData{} defer func() { - session.SendMsg(string(this.module.GetType()), User_SubType_Create, code, &pb.UserCreateRsp{}) + session.SendMsg(string(this.module.GetType()), User_SubType_Create, &pb.UserCreateRsp{}) }() //更新昵称 // update := map[string]interface{}{ // "name": req.NickName, // } - err = this.module.modelUser.GetObj(session.GetUserId(), self) + err := this.module.modelUser.GetObj(session.GetUserId(), self) if err != nil { code = pb.ErrorCode_DBError return @@ -38,5 +38,5 @@ func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interf } event.RegisterGO(comm.Event_CreateUser, session.GetUserId()) - return nil + return } diff --git a/modules/user/api_login.go b/modules/user/api_login.go index aa8879be8..4a61b4430 100644 --- a/modules/user/api_login.go +++ b/modules/user/api_login.go @@ -41,15 +41,15 @@ func (this *Api_Comp) Login_Check(session comm.IUserSession, req *pb.UserLoginRe } //登录 -func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interface{}, req *pb.UserLoginReq) (err error) { +func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interface{}, req *pb.UserLoginReq) (code pb.ErrorCode) { var ( - code pb.ErrorCode + err error db_user *pb.DB_UserData ) defer func() { if db_user != nil { - session.SendMsg(string(this.module.GetType()), User_SubType_Login, code, &pb.UserLoginResp{ + session.SendMsg(string(this.module.GetType()), User_SubType_Login, &pb.UserLoginResp{ Data: db_user, }) event.TriggerEvent(comm.Event_UserLogin, db_user.Uid) @@ -66,7 +66,7 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa db_user, err = this.module.modelUser.User_FindByAccount(user) if err != nil { if err != mongo.ErrNoDocuments { - return err + return } } @@ -127,5 +127,5 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa } } - return err + return }