parent
f2bbd4b924
commit
064c5a8940
@ -0,0 +1,46 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsAddBlackList struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UID string `json:"uid" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddBlacklist(c *gin.Context) {
|
||||||
|
log.Info("", "", "api add blacklist init ....")
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsSearchFriend{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.AddBlacklistReq{
|
||||||
|
Uid: params.UID,
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api add blacklist is server:userID=%s", req.Uid)
|
||||||
|
RpcResp, err := client.AddBlacklist(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call add blacklist rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add blacklist rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call add blacklist rpc server success,args=%s", RpcResp.String())
|
||||||
|
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
log.InfoByArgs("api add blacklist success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsAddFriend struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UID string `json:"uid" binding:"required"`
|
||||||
|
ReqMessage string `json:"reqMessage"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddFriend(c *gin.Context) {
|
||||||
|
log.Info("", "", "api add friend init ....")
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsAddFriend{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.AddFriendReq{
|
||||||
|
Uid: params.UID,
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
ReqMessage: params.ReqMessage,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api add friend is server")
|
||||||
|
RpcResp, err := client.AddFriend(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call add friend rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add friend rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call add friend rpc server success,args=%s", RpcResp.String())
|
||||||
|
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
log.InfoByArgs("api add friend success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsAddFriendResponse struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UID string `json:"uid" binding:"required"`
|
||||||
|
Flag int32 `json:"flag" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddFriendResponse(c *gin.Context) {
|
||||||
|
log.Info("", "", fmt.Sprintf("api add friend response init ...."))
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsAddFriendResponse{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.AddedFriendReq{
|
||||||
|
Uid: params.UID,
|
||||||
|
Flag: params.Flag,
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api add friend response is server:userID=%s", req.Uid)
|
||||||
|
RpcResp, err := client.AddedFriend(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call add_friend_response rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add_friend_response rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call add friend response rpc server success,args=%s", RpcResp.String())
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||||
|
log.InfoByArgs("api add friend response success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsDeleteFriend struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UID string `json:"uid" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteFriend(c *gin.Context) {
|
||||||
|
log.Info("", "", fmt.Sprintf("api delete_friend init ...."))
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsDeleteFriend{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.DeleteFriendReq{
|
||||||
|
Uid: params.UID,
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api delete_friend is server:%s", req.Uid)
|
||||||
|
RpcResp, err := client.DeleteFriend(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call delete_friend rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete_friend rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call delete_friend rpc server,args=%s", RpcResp.String())
|
||||||
|
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
log.InfoByArgs("api delete_friend success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsGetBlackList struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type blackListUserInfo struct {
|
||||||
|
UID string `json:"uid"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Gender int32 `json:"gender"`
|
||||||
|
Mobile string `json:"mobile"`
|
||||||
|
Birth string `json:"birth"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Ex string `json:"ex"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetBlacklist(c *gin.Context) {
|
||||||
|
log.Info("", "", "api get blacklist init ....")
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsGetBlackList{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.GetBlacklistReq{
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, fmt.Sprintf("api get blacklist is server"))
|
||||||
|
RpcResp, err := client.GetBlacklist(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call get_friend_list rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get blacklist rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call get blacklist rpc server success,args=%s", RpcResp.String())
|
||||||
|
if RpcResp.ErrorCode == 0 {
|
||||||
|
userBlackList := make([]blackListUserInfo, 0)
|
||||||
|
for _, friend := range RpcResp.Data {
|
||||||
|
var fi blackListUserInfo
|
||||||
|
fi.UID = friend.Uid
|
||||||
|
fi.Name = friend.Name
|
||||||
|
fi.Icon = friend.Icon
|
||||||
|
fi.Gender = friend.Gender
|
||||||
|
fi.Mobile = friend.Mobile
|
||||||
|
fi.Birth = friend.Birth
|
||||||
|
fi.Email = friend.Email
|
||||||
|
fi.Ex = friend.Ex
|
||||||
|
userBlackList = append(userBlackList, fi)
|
||||||
|
}
|
||||||
|
resp := gin.H{
|
||||||
|
"errCode": RpcResp.ErrorCode,
|
||||||
|
"errMsg": RpcResp.ErrorMsg,
|
||||||
|
"data": userBlackList,
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
} else {
|
||||||
|
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
log.InfoByArgs("api get black list success return,get args=%s,return=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsGetFriendApplyList struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
type UserInfo struct {
|
||||||
|
UID string `json:"uid"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Gender int32 `json:"gender"`
|
||||||
|
Mobile string `json:"mobile"`
|
||||||
|
Birth string `json:"birth"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Ex string `json:"ex"`
|
||||||
|
ReqMessage string `json:"reqMessage"`
|
||||||
|
ApplyTime string `json:"applyTime"`
|
||||||
|
Flag int32 `json:"flag"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFriendApplyList(c *gin.Context) {
|
||||||
|
log.Info("", "", "api get_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)
|
||||||
|
|
||||||
|
params := paramsGetFriendApplyList{}
|
||||||
|
if err := c.BindJSON(¶ms); 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 friend apply list is server")
|
||||||
|
RpcResp, err := client.GetFriendApplyList(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call get friend apply list rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend apply list rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call get friend apply list rpc server success,args=%s", RpcResp.String())
|
||||||
|
if RpcResp.ErrorCode == 0 {
|
||||||
|
userInfoList := make([]UserInfo, 0)
|
||||||
|
for _, applyUserinfo := range RpcResp.Data {
|
||||||
|
var un UserInfo
|
||||||
|
un.UID = applyUserinfo.Uid
|
||||||
|
un.Name = applyUserinfo.Name
|
||||||
|
un.Icon = applyUserinfo.Icon
|
||||||
|
un.Gender = applyUserinfo.Gender
|
||||||
|
un.Mobile = applyUserinfo.Mobile
|
||||||
|
un.Birth = applyUserinfo.Birth
|
||||||
|
un.Email = applyUserinfo.Email
|
||||||
|
un.Ex = applyUserinfo.Ex
|
||||||
|
un.Flag = applyUserinfo.Flag
|
||||||
|
un.ApplyTime = applyUserinfo.ApplyTime
|
||||||
|
un.ReqMessage = applyUserinfo.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 friend apply list success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsGetFriendLIst struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type friendInfo struct {
|
||||||
|
UID string `json:"uid"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Gender int32 `json:"gender"`
|
||||||
|
Mobile string `json:"mobile"`
|
||||||
|
Birth string `json:"birth"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Ex string `json:"ex"`
|
||||||
|
Comment string `json:"comment"`
|
||||||
|
IsInBlackList int32 `json:"isInBlackList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFriendList(c *gin.Context) {
|
||||||
|
log.Info("", "", fmt.Sprintf("api get_friendlist init ...."))
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsGetFriendLIst{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.GetFriendListReq{
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api get friend list is server")
|
||||||
|
RpcResp, err := client.GetFriendList(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call get friend list rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend list rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call get friend list rpc server success,args=%s", RpcResp.String())
|
||||||
|
if RpcResp.ErrorCode == 0 {
|
||||||
|
friendsInfo := make([]friendInfo, 0)
|
||||||
|
for _, friend := range RpcResp.Data {
|
||||||
|
var fi friendInfo
|
||||||
|
fi.UID = friend.Uid
|
||||||
|
fi.Name = friend.Name
|
||||||
|
fi.Icon = friend.Icon
|
||||||
|
fi.Gender = friend.Gender
|
||||||
|
fi.Mobile = friend.Mobile
|
||||||
|
fi.Birth = friend.Birth
|
||||||
|
fi.Email = friend.Email
|
||||||
|
fi.Ex = friend.Ex
|
||||||
|
fi.Comment = friend.Comment
|
||||||
|
fi.IsInBlackList = friend.IsInBlackList
|
||||||
|
friendsInfo = append(friendsInfo, fi)
|
||||||
|
}
|
||||||
|
resp := gin.H{
|
||||||
|
"errCode": RpcResp.ErrorCode,
|
||||||
|
"errMsg": RpcResp.ErrorMsg,
|
||||||
|
"data": friendsInfo,
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
} else {
|
||||||
|
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
log.InfoByArgs("api get friend list success return,get args=%s,return=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsRemoveBlackList struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UID string `json:"uid" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveBlacklist(c *gin.Context) {
|
||||||
|
log.Info("", "", "api remove_blacklist init ....")
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsRemoveBlackList{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.RemoveBlacklistReq{
|
||||||
|
Uid: params.UID,
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api remove blacklist is server:userID=%s", req.Uid)
|
||||||
|
RpcResp, err := client.RemoveBlacklist(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call remove blacklist rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call remove blacklist rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call remove blacklist rpc server success,args=%s", RpcResp.String())
|
||||||
|
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
log.InfoByArgs("api remove blacklist success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsSearchFriend struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UID string `json:"uid" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func SearchFriend(c *gin.Context) {
|
||||||
|
log.Info("", "", fmt.Sprintf("api search friend init ...."))
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsSearchFriend{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.SearchFriendReq{
|
||||||
|
Uid: params.UID,
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api search_friend is server")
|
||||||
|
RpcResp, err := client.SearchFriend(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call search friend rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.InfoByArgs("call search friend rpc server success,args=%s", RpcResp.String())
|
||||||
|
if RpcResp.ErrorCode == 0 {
|
||||||
|
resp := gin.H{
|
||||||
|
"errCode": RpcResp.ErrorCode,
|
||||||
|
"errMsg": RpcResp.ErrorMsg,
|
||||||
|
"data": gin.H{
|
||||||
|
"uid": RpcResp.Data.Uid,
|
||||||
|
"icon": RpcResp.Data.Icon,
|
||||||
|
"name": RpcResp.Data.Name,
|
||||||
|
"gender": RpcResp.Data.Gender,
|
||||||
|
"mobile": RpcResp.Data.Mobile,
|
||||||
|
"birth": RpcResp.Data.Birth,
|
||||||
|
"email": RpcResp.Data.Email,
|
||||||
|
"ex": RpcResp.Data.Ex,
|
||||||
|
"comment": RpcResp.Data.Comment,
|
||||||
|
"isFriend": RpcResp.Data.IsFriend,
|
||||||
|
"isInBlackList": RpcResp.Data.IsInBlackList,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
} else {
|
||||||
|
resp := gin.H{
|
||||||
|
"errCode": RpcResp.ErrorCode,
|
||||||
|
"errMsg": RpcResp.ErrorMsg,
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
log.InfoByArgs("api search_friend success return,get args=%s,return=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package friend
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"Open_IM/src/common/log"
|
||||||
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
|
"context"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type paramsSetFriendComment struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UID string `json:"uid" binding:"required"`
|
||||||
|
Comment string `json:"comment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetFriendComment(c *gin.Context) {
|
||||||
|
log.Info("", "", "api set friend comment init ....")
|
||||||
|
|
||||||
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
|
|
||||||
|
params := paramsSetFriendComment{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.SetFriendCommentReq{
|
||||||
|
Uid: params.UID,
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
Comment: params.Comment,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api set friend comment is server")
|
||||||
|
RpcResp, err := client.SetFriendComment(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,call set friend comment rpc server failed", err)
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call set friend comment rpc server failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Info("", "", "call set friend comment rpc server success,args=%s", RpcResp.String())
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||||
|
log.Info("", "", "api set friend comment success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
Loading…
Reference in new issue