Refactor code

pull/131/head
wenxu12345 3 years ago
parent 288f25c827
commit 2f62339f0c

@ -47,11 +47,11 @@ func main() {
//group related routing group //group related routing group
groupRouterGroup := r.Group("/group") groupRouterGroup := r.Group("/group")
{ {
groupRouterGroup.POST("/create_group", group.CreateGroup) //1 groupRouterGroup.POST("/create_group", group.CreateGroup) //1
groupRouterGroup.POST("/set_group_info", group.SetGroupInfo) //1 groupRouterGroup.POST("/set_group_info", group.SetGroupInfo) //1
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) groupRouterGroup.POST("/group_application_response", group.ApplicationGroupResponse) //1
groupRouterGroup.POST("/transfer_group", group.TransferGroupOwner) groupRouterGroup.POST("/transfer_group", group.TransferGroupOwner)
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

@ -464,7 +464,7 @@ func TransferGroupOwner(c *gin.Context) {
return return
} }
req := &rpc.TransferGroupOwnerReq{} req := &rpc.TransferGroupOwnerReq{}
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 {
@ -483,7 +483,8 @@ func TransferGroupOwner(c *gin.Context) {
return return
} }
resp := api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg} resp := api.TransferGroupOwnerResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
c.JSON(http.StatusOK, resp)
log.NewInfo(req.OperationID, "TransferGroupOwner api return ", resp) log.NewInfo(req.OperationID, "TransferGroupOwner api return ", resp)
c.JSON(http.StatusOK, resp)
} }

@ -595,17 +595,19 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
log.NewInfo(req.OperationID, "TransferGroupOwner ", req.String()) log.NewInfo(req.OperationID, "TransferGroupOwner ", req.String())
if req.OldOwnerUserID == req.NewOwnerUserID { if req.OldOwnerUserID == req.NewOwnerUserID {
log.NewError(req.OperationID, "same owner ", req.String()) log.NewError(req.OperationID, "same owner ", req.OldOwnerUserID, req.NewOwnerUserID)
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
} }
groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: 0} groupMemberInfo := imdb.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: constant.GroupOrdinaryUsers}
err := imdb.UpdateGroupMemberInfo(groupMemberInfo) err := imdb.UpdateGroupMemberInfo(groupMemberInfo)
if err != nil { if err != nil {
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} }
groupMemberInfo = imdb.GroupMember{GroupID: req.GroupID, UserID: req.NewOwnerUserID, RoleLevel: 1} groupMemberInfo = imdb.GroupMember{GroupID: req.GroupID, UserID: req.NewOwnerUserID, RoleLevel: constant.GroupOwner}
err = imdb.UpdateGroupMemberInfo(groupMemberInfo) err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
if err != nil { if err != nil {
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} }
changedType := int32(1) << 4 changedType := int32(1) << 4

@ -149,3 +149,6 @@ type TransferGroupOwnerReq struct {
NewOwnerUserID string `json:"newOwnerUserID" binding:"required"` NewOwnerUserID string `json:"newOwnerUserID" binding:"required"`
OperationID string `json:"operationID" binding:"required"` OperationID string `json:"operationID" binding:"required"`
} }
type TransferGroupOwnerResp struct {
CommResp
}

Loading…
Cancel
Save