Refactor code

pull/131/head
wenxu12345 3 years ago
parent 3ca92c7a03
commit 6c137d9098

@ -25,7 +25,7 @@ func main() {
userRouterGroup := r.Group("/user")
{
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1
userRouterGroup.POST("/get_user_info", user.GetUserInfo) //1
userRouterGroup.POST("/get_user_info", user.GetUserInfo) //1
}
//friend routing group
friendRouterGroup := r.Group("/friend")
@ -35,14 +35,14 @@ func main() {
friendRouterGroup.POST("/get_friend_apply_list", friend.GetFriendApplyList) //1
friendRouterGroup.POST("/get_self_apply_list", friend.GetSelfApplyList) //1
friendRouterGroup.POST("/get_friend_list", friend.GetFriendList) //1
friendRouterGroup.POST("/add_blacklist", friend.AddBlacklist) //1
friendRouterGroup.POST("/get_blacklist", friend.GetBlacklist) //1
friendRouterGroup.POST("/remove_blacklist", friend.RemoveBlacklist) //1
friendRouterGroup.POST("/add_blacklist", friend.AddBlacklist) //1
friendRouterGroup.POST("/get_blacklist", friend.GetBlacklist) //1
friendRouterGroup.POST("/remove_blacklist", friend.RemoveBlacklist) //1
friendRouterGroup.POST("/delete_friend", friend.DeleteFriend)
friendRouterGroup.POST("/add_friend_response", friend.AddFriendResponse) //1
friendRouterGroup.POST("/set_friend_remark", friend.SetFriendRemark) //1
friendRouterGroup.POST("/is_friend", friend.IsFriend) //1
friendRouterGroup.POST("/import_friend", friend.ImportFriend)
friendRouterGroup.POST("/import_friend", friend.ImportFriend) //1
}
//group related routing group
groupRouterGroup := r.Group("/group")
@ -66,7 +66,7 @@ func main() {
authRouterGroup := r.Group("/auth")
{
authRouterGroup.POST("/user_register", apiAuth.UserRegister) //1
authRouterGroup.POST("/user_token", apiAuth.UserToken) //1
authRouterGroup.POST("/user_token", apiAuth.UserToken) //1
}
//Third service
thirdGroup := r.Group("/third")

@ -227,7 +227,10 @@ func CreateGroup(c *gin.Context) {
return
}
req := &rpc.CreateGroupReq{}
utils.CopyStructFields(req, params)
utils.CopyStructFields(req, &params)
for _, v := range params.MemberList {
req.InitMemberList = append(req.InitMemberList, &rpc.GroupAddMemberInfo{UserID: v.UserID, RoleLevel: v.RoleLevel})
}
var ok bool
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
if !ok {
@ -246,13 +249,12 @@ func CreateGroup(c *gin.Context) {
return
}
resp := api.CreateGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
if RpcResp.ErrCode == 0 {
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg, "data": gin.H{"groupInfo": RpcResp.GroupInfo}}
c.JSON(http.StatusOK, resp)
} else {
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg})
utils.CopyStructFields(&resp.GroupInfo, &RpcResp.GroupInfo)
}
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", RpcResp)
c.JSON(http.StatusOK, resp)
}
//my application 我发出去的

@ -1,7 +1,6 @@
package base_info
import (
pb "Open_IM/pkg/proto/group"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
)
@ -77,18 +76,18 @@ type GetGroupAllMemberResp struct {
}
type CreateGroupReq struct {
MemberList []*pb.GroupAddMemberInfo `json:"memberList"`
GroupName string `json:"groupName"`
Introduction string `json:"introduction"`
Notification string `json:"notification"`
FaceUrl string `json:"faceUrl"`
OperationID string `json:"operationID" binding:"required"`
GroupType int32 `json:"groupType"`
Ex string `json:"ex"`
MemberList []*GroupAddMemberInfo `json:"memberList" binding:"required"`
GroupName string `json:"groupName"`
Introduction string `json:"introduction"`
Notification string `json:"notification"`
FaceUrl string `json:"faceUrl"`
OperationID string `json:"operationID" binding:"required"`
GroupType int32 `json:"groupType"`
Ex string `json:"ex"`
}
type CreateGroupResp struct {
CommResp
Data open_im_sdk.GroupInfo `json:"data"`
GroupInfo open_im_sdk.GroupInfo `json:"data"`
}
type GetGroupApplicationListReq struct {

@ -16,6 +16,11 @@ type UserInfo struct {
Ex string `json:"ex" binding:"omitempty,max=1024"`
}
type GroupAddMemberInfo struct {
UserID string `json:"userID" binding:"required"`
RoleLevel int32 `json:"roleLevel" binding:"required"`
}
func SetErrCodeMsg(c *gin.Context, status int) *CommResp {
resp := CommResp{ErrCode: int32(status), ErrMsg: http.StatusText(status)}
c.JSON(status, resp)

Loading…
Cancel
Save