You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/api/friend/friend.go

439 lines
20 KiB

3 years ago
package friend
import (
3 years ago
api "Open_IM/pkg/base_info"
3 years ago
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
3 years ago
rpc "Open_IM/pkg/proto/friend"
3 years ago
"Open_IM/pkg/utils"
"context"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
func AddBlacklist(c *gin.Context) {
3 years ago
params := api.AddBlacklistReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
3 years ago
return
}
3 years ago
req := &rpc.AddBlacklistReq{CommID: &rpc.CommID{}}
3 years ago
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(params.OperationID, "AddBlacklist args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.AddBlacklist(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "AddBlacklist failed ", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add blacklist rpc server failed"})
return
}
3 years ago
resp := api.AddBlacklistResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
3 years ago
log.NewInfo(req.CommID.OperationID, "AddBlacklist api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func ImportFriend(c *gin.Context) {
3 years ago
params := api.ImportFriendReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
3 years ago
return
}
3 years ago
req := &rpc.ImportFriendReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.OperationID, "ImportFriend args ", req.String())
3 years ago
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.ImportFriend(context.Background(), req)
if err != nil {
log.NewError(req.OperationID, "ImportFriend failed", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed " + err.Error()})
return
}
3 years ago
resp := api.ImportFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, Data: RpcResp.FailedFriendUserIDList}
log.NewInfo(req.OperationID, "ImportFriend api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func AddFriend(c *gin.Context) {
3 years ago
params := api.AddFriendReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.AddFriendReq{CommID: &rpc.CommID{}}
3 years ago
utils.CopyStructFields(req.CommID, &params.ParamsCommFriend)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
3 years ago
log.NewInfo(req.CommID.OperationID, "AddFriend args ", req.String())
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.AddFriend(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "AddFriend failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call AddFriend rpc server failed"})
return
}
3 years ago
resp := api.AddFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
3 years ago
log.NewInfo(req.CommID.OperationID, "AddFriend api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func AddFriendResponse(c *gin.Context) {
3 years ago
params := api.AddFriendResponseReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.AddFriendResponseReq{CommID: &rpc.CommID{}}
3 years ago
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String())
3 years ago
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.AddFriendResponse(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "AddFriendResponse failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add_friend_response rpc server failed"})
return
}
3 years ago
resp := api.AddFriendResponseResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
3 years ago
log.NewInfo(req.CommID.OperationID, "AddFriendResponse api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func DeleteFriend(c *gin.Context) {
3 years ago
params := api.DeleteFriendReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.DeleteFriendReq{CommID: &rpc.CommID{}}
3 years ago
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "DeleteFriend args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.DeleteFriend(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "DeleteFriend failed ", err, req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete_friend rpc server failed"})
return
}
3 years ago
resp := api.DeleteFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
log.NewInfo(req.CommID.OperationID, "DeleteFriend api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func GetBlacklist(c *gin.Context) {
3 years ago
params := api.GetBlackListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.GetBlacklistReq{CommID: &rpc.CommID{}}
3 years ago
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "GetBlacklist args ", req.String())
3 years ago
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.GetBlacklist(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "GetBlacklist failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get blacklist rpc server failed"})
return
}
3 years ago
resp := api.GetBlackListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
3 years ago
for _, v := range RpcResp.BlackUserInfoList {
black := api.BlackUserInfo{}
utils.CopyStructFields(&black, v)
resp.BlackUserInfoList = append(resp.BlackUserInfoList, &black)
}
3 years ago
log.NewInfo(req.CommID.OperationID, "GetBlacklist api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func SetFriendComment(c *gin.Context) {
3 years ago
params := api.SetFriendCommentReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.SetFriendCommentReq{CommID: &rpc.CommID{}}
utils.CopyStructFields(req.CommID, &params)
3 years ago
req.Remark = params.Remark
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "SetFriendComment args ", req.String())
3 years ago
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.SetFriendComment(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "SetFriendComment failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call set friend comment rpc server failed"})
return
}
3 years ago
resp := api.SetFriendCommentResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
3 years ago
3 years ago
log.NewInfo(req.CommID.OperationID, "SetFriendComment api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func RemoveBlacklist(c *gin.Context) {
3 years ago
params := api.RemoveBlackListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.RemoveBlacklistReq{CommID: &rpc.CommID{}}
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.RemoveBlacklist(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "RemoveBlacklist failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call remove blacklist rpc server failed"})
return
}
3 years ago
resp := api.RemoveBlackListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist api return ", resp)
3 years ago
}
func IsFriend(c *gin.Context) {
3 years ago
params := api.IsFriendReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.IsFriendReq{CommID: &rpc.CommID{}}
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "IsFriend args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.IsFriend(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "IsFriend failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add friend rpc server failed"})
return
}
3 years ago
resp := api.IsFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, Response: RpcResp.Response}
3 years ago
c.JSON(http.StatusOK, resp)
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
}
3 years ago
//
//func GetFriendsInfo(c *gin.Context) {
// params := api.GetFriendsInfoReq{}
// if err := c.BindJSON(&params); err != nil {
// log.NewError("0", "BindJSON failed ", err.Error())
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
// return
// }
// req := &rpc.GetFriendsInfoReq{}
// utils.CopyStructFields(req.CommID, params)
// var ok bool
// ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
// if !ok {
// log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
// return
// }
// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
//
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
// client := rpc.NewFriendClient(etcdConn)
// RpcResp, err := client.GetFriendsInfo(context.Background(), req)
// if err != nil {
// log.NewError(req.CommID.OperationID, "GetFriendsInfo failed ", err.Error(), req.String())
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
// return
// }
//
// resp := api.GetFriendsInfoResp{CommResp:api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
// utils.CopyStructFields(&resp, RpcResp)
// c.JSON(http.StatusOK, resp)
// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo api return ", resp)
//}
3 years ago
func GetFriendList(c *gin.Context) {
3 years ago
params := api.GetFriendListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.GetFriendListReq{CommID: &rpc.CommID{}}
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "GetFriendList args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.GetFriendList(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "GetFriendList failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend list rpc server failed"})
return
}
3 years ago
resp := api.GetFriendListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendInfoList: RpcResp.FriendInfoList}
3 years ago
log.NewInfo(req.CommID.OperationID, "GetFriendList api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func GetFriendApplyList(c *gin.Context) {
3 years ago
params := api.GetFriendApplyListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.GetFriendApplyListReq{CommID: &rpc.CommID{}}
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.GetFriendApplyList(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "GetFriendApplyList failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend apply list rpc server failed"})
return
}
3 years ago
resp := api.GetFriendApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
3 years ago
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList api return ", resp)
3 years ago
}
func GetSelfApplyList(c *gin.Context) {
3 years ago
params := api.GetSelfApplyListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.GetSelfApplyListReq{CommID: &rpc.CommID{}}
utils.CopyStructFields(req.CommID, &params)
3 years ago
var ok bool
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
return
}
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
3 years ago
client := rpc.NewFriendClient(etcdConn)
3 years ago
RpcResp, err := client.GetSelfApplyList(context.Background(), req)
if err != nil {
log.NewError(req.CommID.OperationID, "GetSelfApplyList failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get self apply list rpc server failed"})
return
}
3 years ago
resp := api.GetSelfApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
3 years ago
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}