Refactor code

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

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

@ -24,7 +24,7 @@ func KickGroupMember(c *gin.Context) {
} }
req := &rpc.KickGroupMemberReq{} req := &rpc.KickGroupMemberReq{}
utils.CopyStructFields(req, params) utils.CopyStructFields(req, &params)
var ok bool var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token")) ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok { if !ok {
@ -39,7 +39,7 @@ func KickGroupMember(c *gin.Context) {
client := rpc.NewGroupClient(etcdConn) client := rpc.NewGroupClient(etcdConn)
RpcResp, err := client.KickGroupMember(context.Background(), req) RpcResp, err := client.KickGroupMember(context.Background(), req)
if err != nil { 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()}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return return
} }
@ -48,8 +48,12 @@ func KickGroupMember(c *gin.Context) {
memberListResp.ErrMsg = RpcResp.ErrMsg memberListResp.ErrMsg = RpcResp.ErrMsg
memberListResp.ErrCode = RpcResp.ErrCode memberListResp.ErrCode = RpcResp.ErrCode
for _, v := range RpcResp.Id2ResultList { 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) log.NewInfo(req.OperationID, "KickGroupMember api return ", memberListResp)
c.JSON(http.StatusOK, memberListResp) c.JSON(http.StatusOK, memberListResp)
} }
@ -180,7 +184,7 @@ func GetJoinedGroupList(c *gin.Context) {
return 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) c.JSON(http.StatusOK, GroupListResp)
log.NewInfo(req.OperationID, "GetJoinedGroupList api return ", 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}} Resp := api.InviteUserToGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
for _, v := range RpcResp.Id2ResultList { 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) c.JSON(http.StatusOK, Resp)
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", 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) ownerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
if err != nil { if err != nil {
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID) 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? //op is group owner?
var flag = 0 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) log.NewError(req.OperationID, "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1}) resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
} else { } else {
log.NewDebug(req.OperationID, "kicked ", v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: 0}) resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: 0})
okUserIDList = append(okUserIDList, v) okUserIDList = append(okUserIDList, v)
} }

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

Loading…
Cancel
Save