From b4ec3d86fb72fd08e4cbedc9be62c34b7b3c73da Mon Sep 17 00:00:00 2001 From: zhaocy Date: Wed, 15 Jun 2022 19:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9api=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api_addblack.go | 9 ++++++--- modules/friend/api_agree.go | 11 +++++++---- modules/friend/api_apply.go | 9 ++++++--- modules/friend/api_applylist.go | 7 +++++-- modules/friend/api_blacklist.go | 7 +++++-- modules/friend/api_del.go | 7 +++++-- modules/friend/api_delblack.go | 9 ++++++--- modules/friend/api_list.go | 7 +++++-- modules/friend/api_refuse.go | 9 ++++++--- modules/friend/api_search.go | 9 ++++++--- modules/model_comp.go | 26 ++++++++++++++++---------- modules/user/api_create.go | 2 +- modules/user/api_login.go | 8 ++++---- 13 files changed, 78 insertions(+), 42 deletions(-) diff --git a/modules/friend/api_addblack.go b/modules/friend/api_addblack.go index c400f39e8..5454f0615 100644 --- a/modules/friend/api_addblack.go +++ b/modules/friend/api_addblack.go @@ -1,14 +1,17 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" ) +func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.FriendBlackAddReq) (result map[string]interface{}, code pb.ErrorCode) { + return +} + //加入黑名单 -func (this *ApiComp) Addblack(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackAddReq) (err error) { +func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackAddReq) (err error) { var ( code pb.ErrorCode self *pb.DB_FriendData @@ -61,6 +64,6 @@ func (this *ApiComp) Addblack(ctx context.Context, session comm.IUserSession, re self.BlackIds = append(self.BlackIds, req.FriendId) //更新黑名单 - this.module.model_friend.SetObj(self.UserId, self, false) + this.module.model_friend.SetObj(self.UserId, self, false, true) return nil } diff --git a/modules/friend/api_agree.go b/modules/friend/api_agree.go index 99db6fc48..ad6752942 100644 --- a/modules/friend/api_agree.go +++ b/modules/friend/api_agree.go @@ -1,14 +1,17 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" ) +func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.FriendAgreeReq) (result map[string]interface{}, code pb.ErrorCode) { + return +} + //单个/批量同意 -func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeReq) (err error) { +func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendAgreeReq) (err error) { var ( code pb.ErrorCode self *pb.DB_FriendData @@ -49,7 +52,7 @@ func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req * if _, ok := utils.Find(target.FriendIds, self.UserId); !ok { target.FriendIds = append(target.FriendIds, self.UserId) } - this.module.model_friend.SetObj(target.UserId, target, false) + this.module.model_friend.SetObj(target.UserId, target, false, true) } //将申请人从申请列表中删除 @@ -59,5 +62,5 @@ func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req * } //更新 - return this.module.model_friend.SetObj(self.UserId, self, false) + return this.module.model_friend.SetObj(self.UserId, self, false, true) } diff --git a/modules/friend/api_apply.go b/modules/friend/api_apply.go index 33ef0af10..7ca176782 100644 --- a/modules/friend/api_apply.go +++ b/modules/friend/api_apply.go @@ -1,15 +1,18 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/utils" ) +func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //好友申请 -func (this *ApiComp) Apply(ctx context.Context, session comm.IUserSession, req *pb.FriendApplyReq) (err error) { +func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyReq) (err error) { var ( code pb.ErrorCode self *pb.DB_FriendData @@ -94,7 +97,7 @@ func (this *ApiComp) Apply(ctx context.Context, session comm.IUserSession, req * err = this.module.model_friend.SetObj(req.FriendId, &pb.DB_FriendData{ UserId: req.FriendId, ApplyIds: target.ApplyIds, - }, false) + }, 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 ad65bf7fd..79e524993 100644 --- a/modules/friend/api_applylist.go +++ b/modules/friend/api_applylist.go @@ -1,13 +1,16 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" ) +func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.FriendApplyListReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //申请列表 -func (this *ApiComp) ApplyList(ctx context.Context, session comm.IUserSession, req *pb.FriendApplyListReq) (err error) { +func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyListReq) (err error) { var ( code pb.ErrorCode self *pb.DB_FriendData diff --git a/modules/friend/api_blacklist.go b/modules/friend/api_blacklist.go index fe5d50d46..af66da77f 100644 --- a/modules/friend/api_blacklist.go +++ b/modules/friend/api_blacklist.go @@ -1,13 +1,16 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" ) +func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.FriendBlackListReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //黑名单 -func (this *ApiComp) Blacklist(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackListReq) (err error) { +func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackListReq) (err error) { var ( code pb.ErrorCode self *pb.DB_FriendData diff --git a/modules/friend/api_del.go b/modules/friend/api_del.go index 8e0ffcc16..128066d67 100644 --- a/modules/friend/api_del.go +++ b/modules/friend/api_del.go @@ -1,12 +1,15 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" ) +func (this *ApiComp) Del_Check(session comm.IUserSession, req *pb.FriendDelReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //删除好友 -func (this *ApiComp) Del(ctx context.Context, session comm.IUserSession, req *pb.FriendDelReq) error { +func (this *ApiComp) Del(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelReq) error { return nil } diff --git a/modules/friend/api_delblack.go b/modules/friend/api_delblack.go index 8d5c961b9..2e8dea605 100644 --- a/modules/friend/api_delblack.go +++ b/modules/friend/api_delblack.go @@ -1,14 +1,17 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" ) +func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.FriendDelBlackReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //删除黑名单 -func (this *ApiComp) delblack(ctx context.Context, session comm.IUserSession, req *pb.FriendDelBlackReq) (err error) { +func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelBlackReq) (err error) { var ( code pb.ErrorCode self *pb.DB_FriendData @@ -32,6 +35,6 @@ func (this *ApiComp) delblack(ctx context.Context, session comm.IUserSession, re //从黑名单列表中删除目标 self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId) //更新黑名单 - return this.module.model_friend.SetObj(self.UserId, self, false) + return this.module.model_friend.SetObj(self.UserId, self, false, true) } diff --git a/modules/friend/api_list.go b/modules/friend/api_list.go index a7d6b5872..9d4bfc0b9 100644 --- a/modules/friend/api_list.go +++ b/modules/friend/api_list.go @@ -1,13 +1,16 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" ) +func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.FriendListReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //好友列表 -func (this *ApiComp) List(ctx context.Context, session comm.IUserSession, req *pb.FriendListReq) (err error) { +func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendListReq) (err error) { var ( code pb.ErrorCode self *pb.DB_FriendData diff --git a/modules/friend/api_refuse.go b/modules/friend/api_refuse.go index 6199b0bad..45f1b9e8e 100644 --- a/modules/friend/api_refuse.go +++ b/modules/friend/api_refuse.go @@ -1,14 +1,17 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" ) +func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.FriendRefuseReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //单个/批量拒绝 -func (this *ApiComp) Refuse(ctx context.Context, session comm.IUserSession, req *pb.FriendRefuseReq) (err error) { +func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendRefuseReq) (err error) { //将申请人从申请列表中删除 var ( code pb.ErrorCode @@ -38,5 +41,5 @@ func (this *ApiComp) Refuse(ctx context.Context, session comm.IUserSession, req } //更新 - return this.module.model_friend.SetObj(self.UserId, self, false) + return this.module.model_friend.SetObj(self.UserId, self, false, true) } diff --git a/modules/friend/api_search.go b/modules/friend/api_search.go index a5a187a3c..e20a1dadf 100644 --- a/modules/friend/api_search.go +++ b/modules/friend/api_search.go @@ -1,13 +1,16 @@ package friend import ( - "context" "go_dreamfactory/comm" "go_dreamfactory/pb" ) +func (this *ApiComp) Search_Check(session comm.IUserSession, req *pb.FriendSearchReq) (chk map[string]interface{}, code pb.ErrorCode) { + return +} + //搜索 -func (this *ApiComp) Search(ctx context.Context, session comm.IUserSession, req *pb.FriendSearchReq) error { +func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendSearchReq) error { var ( code pb.ErrorCode rsp *pb.FriendSearchRsp @@ -22,7 +25,7 @@ func (this *ApiComp) Search(ctx context.Context, session comm.IUserSession, req session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, code, rsp) }() - user :=this.module.model_friend.Frined_FindCond(req.NickName) + user := this.module.model_friend.Frined_FindCond(req.NickName) if user != nil { friend = &pb.FriendBase{ UserId: user.Uid, diff --git a/modules/model_comp.go b/modules/model_comp.go index 05f56da92..3bda04061 100644 --- a/modules/model_comp.go +++ b/modules/model_comp.go @@ -98,34 +98,40 @@ func (this *Model_Comp) UpdateModelLogs(table string, uID string, where interfac return err } -func (this *Model_Comp) SetObj(uid string, data proto.Message, isnew bool) error { +func (this *Model_Comp) SetObj(uid string, data proto.Message, isnew, islog bool) error { err := this.Redis.Set(fmt.Sprintf("%s:%s", this.Prefix, uid), data, 0) if err != nil { log.Errorf("set err:%v", err) return err } - if isnew { - return this.InsertModelLogs(this.Prefix, uid, data) - } else { - return this.UpdateModelLogs(this.Prefix, uid, bson.M{"_id": uid}, data) + if islog { + if isnew { + return this.InsertModelLogs(this.Prefix, uid, data) + } else { + return this.UpdateModelLogs(this.Prefix, uid, bson.M{"_id": uid}, data) + } } + return nil } //更新缓存字段 //isnew true insertlog , false updatelog -func (this *Model_Comp) Set(uid string, v map[string]interface{}, isnew bool) error { +func (this *Model_Comp) Set(uid string, v map[string]interface{}, isnew, islog bool) error { err := this.Redis.HMSet(fmt.Sprintf("%s:%s", this.Prefix, uid), v) if err != nil { log.Errorf("set err:%v", err) return err } - if isnew { - return this.InsertModelLogs(this.Prefix, uid, v) - } else { - return this.UpdateModelLogs(this.Prefix, uid, bson.M{"_id": uid}, v) + if islog { + if isnew { + return this.InsertModelLogs(this.Prefix, uid, v) + } else { + return this.UpdateModelLogs(this.Prefix, uid, bson.M{"_id": uid}, v) + } } + return nil } func (this *Model_Comp) GetObj(uid string, v interface{}) error { diff --git a/modules/user/api_create.go b/modules/user/api_create.go index b82b2f069..70f98e333 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -24,7 +24,7 @@ func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interf update := map[string]interface{}{ "name": req.NickName, } - err = this.module.modelUser.Set(session.GetUserId(), update, false) + err = this.module.modelUser.Set(session.GetUserId(), update, false, true) if err != nil { code = pb.ErrorCode_DBError return diff --git a/modules/user/api_login.go b/modules/user/api_login.go index b58a586ae..df76ab128 100644 --- a/modules/user/api_login.go +++ b/modules/user/api_login.go @@ -86,20 +86,20 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa return } session.Bind(user.Uid, this.service.GetId()) - cache_user.Uid = user.Uid // data := map[string]interface{}{ // "sessionId": cache_user.SessionId, // "gatewayServiceId": cache_user.GatewayServiceId, // } data := &pb.Cache_UserData{ + Uid: user.Uid, SessionId: cache_user.SessionId, GatewayServiceId: cache_user.GatewayServiceId, } - return this.module.modelUser.SetObj(cache_user.Uid, data, true) + return this.module.modelUser.SetObj(cache_user.Uid, data, true, true) } else { session.Bind(db_user.Uid, this.service.GetId()) - cache_user.Uid = db_user.Uid data := &pb.Cache_UserData{ + Uid: db_user.Uid, SessionId: cache_user.SessionId, GatewayServiceId: cache_user.GatewayServiceId, } @@ -107,6 +107,6 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa // "sessionId": cache_user.SessionId, // "gatewayServiceId": cache_user.GatewayServiceId, // } - return this.module.modelUser.SetObj(cache_user.Uid, data, false) + return this.module.modelUser.SetObj(cache_user.Uid, data, false, false) } }