mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 00:55:59 +08:00
api
This commit is contained in:
@@ -290,13 +290,13 @@ func GetRecvGroupApplicationList(c *gin.Context) {
|
||||
}
|
||||
req := &rpc.GetGroupApplicationListReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
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
|
||||
}
|
||||
//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, "GetGroupApplicationList args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
@@ -314,6 +314,37 @@ func GetRecvGroupApplicationList(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUserReqGroupApplicationList(c *gin.Context) {
|
||||
var params api.GetUserReqGroupApplicationListReq
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetUserReqApplicationListReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
//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, "GetGroupsInfo args ", req.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.GetUserReqApplicationList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupsInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, RpcResp)
|
||||
resp := api.GetGroupApplicationListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, GroupRequestList: RpcResp.GroupRequestList}
|
||||
log.NewInfo(req.OperationID, "GetGroupApplicationList api return ", resp)
|
||||
resp.Data = jsonData.JsonDataList(resp.GroupRequestList)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetGroupsInfo(c *gin.Context) {
|
||||
params := api.GetGroupInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
|
||||
@@ -638,3 +638,41 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbGroup.GetUserReqApplicationListResp{}
|
||||
groupRequests, err := imdb.GetUserReqGroupByUserID(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserReqGroupByUserID failed ", err.Error())
|
||||
resp.CommonResp = &pbGroup.CommonResp{
|
||||
ErrCode: constant.ErrDB.ErrCode,
|
||||
ErrMsg: constant.ErrDB.ErrMsg,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
for _, groupReq := range groupRequests {
|
||||
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupReq.GroupID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupReq.GroupID)
|
||||
continue
|
||||
}
|
||||
user, err := imdb.GetUserByUserID(groupReq.UserID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetUserByUserID failed ", err.Error(), groupReq.UserID)
|
||||
continue
|
||||
}
|
||||
cp.GroupRequestDBCopyOpenIM(&node, &groupReq)
|
||||
cp.UserDBCopyOpenIMPublicUser(node.UserInfo, user)
|
||||
cp.GroupDBCopyOpenIM(node.GroupInfo, group)
|
||||
resp.GroupRequestList = append(resp.GroupRequestList, &node)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), groupRequests)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "output:", resp)
|
||||
resp.CommonResp = &pbGroup.CommonResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user