Refactor code

pull/131/head
wenxu12345 3 years ago
parent 492915567b
commit a031311ab5

@ -52,9 +52,9 @@ func main() {
groupRouterGroup.POST("join_group", group.JoinGroup) //1
groupRouterGroup.POST("/quit_group", group.QuitGroup) //1
groupRouterGroup.POST("/group_application_response", group.ApplicationGroupResponse) //1
groupRouterGroup.POST("/transfer_group", group.TransferGroupOwner)
groupRouterGroup.POST("/get_group_applicationList", group.GetGroupApplicationList) //1
groupRouterGroup.POST("/get_groups_info", group.GetGroupsInfo) //1
groupRouterGroup.POST("/transfer_group", group.TransferGroupOwner) //1
groupRouterGroup.POST("/get_group_applicationList", group.GetGroupApplicationList) //1
groupRouterGroup.POST("/get_groups_info", group.GetGroupsInfo) //1
groupRouterGroup.POST("/kick_group", group.KickGroupMember)
groupRouterGroup.POST("/get_group_member_list", group.GetGroupMemberList)
groupRouterGroup.POST("/get_group_all_member_list", group.GetGroupAllMember)

@ -24,7 +24,7 @@ func KickGroupMember(c *gin.Context) {
}
req := &rpc.KickGroupMemberReq{}
utils.CopyStructFields(req, params)
utils.CopyStructFields(req, &params)
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
@ -39,7 +39,7 @@ func KickGroupMember(c *gin.Context) {
client := rpc.NewGroupClient(etcdConn)
RpcResp, err := client.KickGroupMember(context.Background(), req)
if err != nil {
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error())
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
@ -48,8 +48,12 @@ func KickGroupMember(c *gin.Context) {
memberListResp.ErrMsg = RpcResp.ErrMsg
memberListResp.ErrCode = RpcResp.ErrCode
for _, v := range RpcResp.Id2ResultList {
memberListResp.Data = append(memberListResp.Data, &api.Id2Result{UserID: v.UserID, Result: v.Result})
memberListResp.UserIDResultList = append(memberListResp.UserIDResultList, &api.UserIDResult{UserID: v.UserID, Result: v.Result})
}
if len(memberListResp.UserIDResultList) == 0 {
memberListResp.UserIDResultList = []*api.UserIDResult{}
}
log.NewInfo(req.OperationID, "KickGroupMember api return ", memberListResp)
c.JSON(http.StatusOK, memberListResp)
}
@ -180,7 +184,7 @@ func GetJoinedGroupList(c *gin.Context) {
return
}
GroupListResp := api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, Data: RpcResp.GroupList}
GroupListResp := api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, GroupInfoList: RpcResp.GroupList}
c.JSON(http.StatusOK, GroupListResp)
log.NewInfo(req.OperationID, "GetJoinedGroupList api return ", GroupListResp)
}
@ -214,7 +218,7 @@ func InviteUserToGroup(c *gin.Context) {
Resp := api.InviteUserToGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
for _, v := range RpcResp.Id2ResultList {
Resp.Data = append(Resp.Data, api.Id2Result{UserID: v.UserID, Result: v.Result})
Resp.UserIDResultList = append(Resp.UserIDResultList, api.UserIDResult{UserID: v.UserID, Result: v.Result})
}
c.JSON(http.StatusOK, Resp)
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", Resp)

@ -300,7 +300,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
ownerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
//op is group owner?
var flag = 0
@ -352,6 +352,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
log.NewError(req.OperationID, "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
} else {
log.NewDebug(req.OperationID, "kicked ", v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: 0})
okUserIDList = append(okUserIDList, v)
}

@ -9,10 +9,6 @@ type CommResp struct {
ErrCode int32 `json:"errCode"`
ErrMsg string `json:"errMsg"`
}
type Id2Result struct {
UserID string `json:"userID"`
Result int32 `json:"result"`
}
type KickGroupMemberReq struct {
GroupID string `json:"groupID" binding:"required"`
@ -22,7 +18,7 @@ type KickGroupMemberReq struct {
}
type KickGroupMemberResp struct {
CommResp
Data []*Id2Result `json:"data"`
UserIDResultList []*UserIDResult `json:"data"`
}
type GetGroupMembersInfoReq struct {
@ -43,7 +39,7 @@ type InviteUserToGroupReq struct {
}
type InviteUserToGroupResp struct {
CommResp
Data []Id2Result `json:"data"`
UserIDResultList []UserIDResult `json:"data"`
}
type GetJoinedGroupListReq struct {
@ -52,7 +48,7 @@ type GetJoinedGroupListReq struct {
}
type GetJoinedGroupListResp struct {
CommResp
Data []*open_im_sdk.GroupInfo `json:"data"`
GroupInfoList []*open_im_sdk.GroupInfo `json:"data"`
}
type GetGroupMemberListReq struct {

Loading…
Cancel
Save