mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-27 03:58:55 +08:00
friend api
This commit is contained in:
parent
ca0ee35d46
commit
b699fd899a
@ -30,14 +30,14 @@ func AddFriendResponse(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &pbFriend.AddedFriendReq{
|
req := &pbFriend.AddFriendResponseReq{
|
||||||
Uid: params.UID,
|
Uid: params.UID,
|
||||||
Flag: params.Flag,
|
Flag: params.Flag,
|
||||||
OperationID: params.OperationID,
|
OperationID: params.OperationID,
|
||||||
Token: c.Request.Header.Get("token"),
|
Token: c.Request.Header.Get("token"),
|
||||||
}
|
}
|
||||||
log.Info(req.Token, req.OperationID, "api add friend response is server:userID=%s", req.Uid)
|
log.Info(req.Token, req.OperationID, "api add friend response is server:userID=%s", req.Uid)
|
||||||
RpcResp, err := client.AddedFriend(context.Background(), req)
|
RpcResp, err := client.AddFriendResponse(context.Background(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,call add_friend_response rpc server failed", err)
|
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"})
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add_friend_response rpc server failed"})
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type paramsGetFriendApplyList struct {
|
type paramsGetApplyList struct {
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
}
|
}
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
@ -35,7 +35,7 @@ func GetFriendApplyList(c *gin.Context) {
|
|||||||
client := pbFriend.NewFriendClient(etcdConn)
|
client := pbFriend.NewFriendClient(etcdConn)
|
||||||
defer etcdConn.Close()
|
defer etcdConn.Close()
|
||||||
|
|
||||||
params := paramsGetFriendApplyList{}
|
params := paramsGetApplyList{}
|
||||||
if err := c.BindJSON(¶ms); err != nil {
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
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())
|
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(¶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 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())
|
||||||
|
}
|
||||||
|
69
src/api/friend/get_friends_info.go
Normal file
69
src/api/friend/get_friends_info.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
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 GetFriendsInfo(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)
|
||||||
|
defer etcdConn.Close()
|
||||||
|
|
||||||
|
params := paramsSearchFriend{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.GetFriendsInfoReq{
|
||||||
|
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.GetFriendsInfo(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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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())
|
||||||
|
}
|
47
src/api/friend/is_friend.go
Normal file
47
src/api/friend/is_friend.go
Normal file
@ -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 paramsIsFriend struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
ReceiveUid string `json:"receive_uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsFriend(c *gin.Context) {
|
||||||
|
log.Info("", "", "api is friend 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 := paramsIsFriend{}
|
||||||
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req := &pbFriend.IsFriendReq{
|
||||||
|
OperationID: params.OperationID,
|
||||||
|
ReceiveUid: params.OperationID,
|
||||||
|
Token: c.Request.Header.Get("token"),
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, "api is friend is server")
|
||||||
|
RpcResp, err := client.IsFriend(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 is friend rpc server success,args=%s", RpcResp.String())
|
||||||
|
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "isFriend": RpcResp.ShipType}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
log.InfoByArgs("api is friend success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user