friend api

This commit is contained in:
away
2021-06-28 15:27:20 +08:00
parent ca0ee35d46
commit b699fd899a
4 changed files with 170 additions and 4 deletions
+52 -2
View File
@@ -11,7 +11,7 @@ import (
"strings"
)
type paramsGetFriendApplyList struct {
type paramsGetApplyList struct {
OperationID string `json:"operationID" binding:"required"`
}
type UserInfo struct {
@@ -35,7 +35,7 @@ func GetFriendApplyList(c *gin.Context) {
client := pbFriend.NewFriendClient(etcdConn)
defer etcdConn.Close()
params := paramsGetFriendApplyList{}
params := paramsGetApplyList{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
@@ -77,3 +77,53 @@ func GetFriendApplyList(c *gin.Context) {
}
log.InfoByArgs("api get friend apply list success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}
func GetSelfApplyList(c *gin.Context) {
log.Info("", "", "api get self friend apply list init ....")
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
defer etcdConn.Close()
params := paramsGetApplyList{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
req := &pbFriend.GetFriendApplyReq{
OperationID: params.OperationID,
Token: c.Request.Header.Get("token"),
}
log.Info(req.Token, req.OperationID, "api get self apply list is server")
RpcResp, err := client.GetSelfApplyList(context.Background(), req)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,call get self apply list rpc server failed", err)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get self apply list rpc server failed"})
return
}
log.InfoByArgs("call get self apply list rpc server success,args=%s", RpcResp.String())
if RpcResp.ErrorCode == 0 {
userInfoList := make([]UserInfo, 0)
for _, selfApplyOtherUserinfo := range RpcResp.Data {
var un UserInfo
un.UID = selfApplyOtherUserinfo.Uid
un.Name = selfApplyOtherUserinfo.Name
un.Icon = selfApplyOtherUserinfo.Icon
un.Gender = selfApplyOtherUserinfo.Gender
un.Mobile = selfApplyOtherUserinfo.Mobile
un.Birth = selfApplyOtherUserinfo.Birth
un.Email = selfApplyOtherUserinfo.Email
un.Ex = selfApplyOtherUserinfo.Ex
un.Flag = selfApplyOtherUserinfo.Flag
un.ApplyTime = selfApplyOtherUserinfo.ApplyTime
un.ReqMessage = selfApplyOtherUserinfo.ReqMessage
userInfoList = append(userInfoList, un)
}
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": userInfoList}
c.JSON(http.StatusOK, resp)
} else {
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
c.JSON(http.StatusOK, resp)
}
log.InfoByArgs("api get self apply list success return,get args=%s,return args=%s", req.String(), RpcResp.String())
}