48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) SearchCheck(session comm.IUserSession, req *pb.FriendSearchReq) (code pb.ErrorCode) {
|
|
if req.NickName == "" {
|
|
code = pb.ErrorCode_FriendSearchNameEmpty
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//搜索
|
|
func (this *apiComp) Search(session comm.IUserSession, req *pb.FriendSearchReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.SearchCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
var (
|
|
Resp *pb.FriendSearchResp
|
|
friend *pb.FriendBase
|
|
)
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
Resp = &pb.FriendSearchResp{
|
|
Friend: friend,
|
|
}
|
|
}
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeSearch, Resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
}()
|
|
|
|
user := this.moduleFriend.modelFriend.Frined_FindCond(req.NickName)
|
|
if user != nil {
|
|
friend = &pb.FriendBase{
|
|
UserId: user.Uid,
|
|
NickName: user.Name,
|
|
}
|
|
}
|
|
return
|
|
}
|