From da5e60a0096784f98cd44f0383dca35e52da74f5 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 18 Jan 2022 15:26:06 +0800 Subject: [PATCH 1/9] Refactor code --- internal/api/group/group.go | 1 + pkg/base_info/group_api_struct.go | 2 +- pkg/common/db/mysql.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/api/group/group.go b/internal/api/group/group.go index 61bc95495..16ce528fa 100644 --- a/internal/api/group/group.go +++ b/internal/api/group/group.go @@ -167,6 +167,7 @@ func GetGroupAllMemberList(c *gin.Context) { func GetJoinedGroupList(c *gin.Context) { params := api.GetJoinedGroupListReq{} + err := c.BindJSON(¶ms) if err := c.BindJSON(¶ms); err != nil { log.NewError("0", "BindJSON failed ", err.Error()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) diff --git a/pkg/base_info/group_api_struct.go b/pkg/base_info/group_api_struct.go index 01ba3da84..0ecaba7c2 100644 --- a/pkg/base_info/group_api_struct.go +++ b/pkg/base_info/group_api_struct.go @@ -90,7 +90,7 @@ type CreateGroupReq struct { } type CreateGroupResp struct { CommResp - GroupInfo open_im_sdk.GroupInfo `jason:-` + GroupInfo open_im_sdk.GroupInfo `json:-` Data map[string]interface{} `json:"data"` } diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go index dba24ae61..2540ea7d9 100644 --- a/pkg/common/db/mysql.go +++ b/pkg/common/db/mysql.go @@ -44,7 +44,7 @@ func initMysqlDB() { db.Close() dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", - config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName+"test1") + config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) db, err = gorm.Open("mysql", dsn) if err != nil { log.NewError("0", "Open failed ", err.Error(), dsn) From f4ceef485b51a5285f5eb7f118169c3be963c958 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 18 Jan 2022 15:58:57 +0800 Subject: [PATCH 2/9] Refactor code --- pkg/base_info/group_api_struct.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/base_info/group_api_struct.go b/pkg/base_info/group_api_struct.go index 0ecaba7c2..9847ef1c5 100644 --- a/pkg/base_info/group_api_struct.go +++ b/pkg/base_info/group_api_struct.go @@ -90,7 +90,7 @@ type CreateGroupReq struct { } type CreateGroupResp struct { CommResp - GroupInfo open_im_sdk.GroupInfo `json:-` + GroupInfo open_im_sdk.GroupInfo `json:"-"` Data map[string]interface{} `json:"data"` } From e28a8db3b4aafc284b17cd69b083ae032c4135df Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 18 Jan 2022 19:46:17 +0800 Subject: [PATCH 3/9] Refactor code --- internal/api/group/group.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/api/group/group.go b/internal/api/group/group.go index 16ce528fa..61bc95495 100644 --- a/internal/api/group/group.go +++ b/internal/api/group/group.go @@ -167,7 +167,6 @@ func GetGroupAllMemberList(c *gin.Context) { func GetJoinedGroupList(c *gin.Context) { params := api.GetJoinedGroupListReq{} - err := c.BindJSON(¶ms) if err := c.BindJSON(¶ms); err != nil { log.NewError("0", "BindJSON failed ", err.Error()) c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) From d132e53c064f6ff07a27edaafc9aaff0d5f512f0 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 18 Jan 2022 20:04:58 +0800 Subject: [PATCH 4/9] Refactor code --- internal/api/group/group.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/api/group/group.go b/internal/api/group/group.go index 61bc95495..4497a1578 100644 --- a/internal/api/group/group.go +++ b/internal/api/group/group.go @@ -245,8 +245,9 @@ func CreateGroup(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) return } - req := &rpc.CreateGroupReq{} - utils.CopyStructFields(req, ¶ms) + req := &rpc.CreateGroupReq{GroupInfo: &open_im_sdk.GroupInfo{}} + utils.CopyStructFields(req.GroupInfo, ¶ms) + for _, v := range params.MemberList { req.InitMemberList = append(req.InitMemberList, &rpc.GroupAddMemberInfo{UserID: v.UserID, RoleLevel: v.RoleLevel}) } From 28d9304ec6d87a58979f4c472837690f2d5ca945 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 18 Jan 2022 20:27:46 +0800 Subject: [PATCH 5/9] Refactor code --- internal/api/user/user.go | 5 ++--- pkg/base_info/user_api_struct.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/api/user/user.go b/internal/api/user/user.go index c57eeb88d..8508cddc8 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -115,13 +115,12 @@ func GetSelfUserInfo(c *gin.Context) { return } if len(RpcResp.UserInfoList) == 1 { - resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: RpcResp.UserInfoList[0]} - resp.Data = jsonData.JsonDataList(resp.UserInfoList) + resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfo: RpcResp.UserInfoList[0]} + resp.Data = jsonData.JsonDataOne(resp.UserInfo) log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } else { resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} - resp.Data = jsonData.JsonDataList(resp.UserInfoList) log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } diff --git a/pkg/base_info/user_api_struct.go b/pkg/base_info/user_api_struct.go index 3ca191f98..2ccfc6cc6 100644 --- a/pkg/base_info/user_api_struct.go +++ b/pkg/base_info/user_api_struct.go @@ -29,6 +29,6 @@ type GetSelfUserInfoReq struct { } type GetSelfUserInfoResp struct { CommResp - UserInfoList *open_im_sdk.UserInfo `json:"-"` - Data []map[string]interface{} `json:"data"` + UserInfo *open_im_sdk.UserInfo `json:"-"` + Data map[string]interface{} `json:"data"` } From 0dc5c9dbac602c3b913c841aa8410984bb4d4e72 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 18 Jan 2022 21:17:35 +0800 Subject: [PATCH 6/9] Refactor code --- internal/api/group/group.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/api/group/group.go b/internal/api/group/group.go index 4497a1578..85473b4c2 100644 --- a/internal/api/group/group.go +++ b/internal/api/group/group.go @@ -258,6 +258,8 @@ func CreateGroup(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) return } + req.OwnerUserID = req.OpUserID + req.OperationID = params.OperationID log.NewInfo(req.OperationID, "CreateGroup args ", req.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) From 1c362e487138b787c08d53757a8e5ae8c75bc37d Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 18 Jan 2022 21:42:27 +0800 Subject: [PATCH 7/9] Refactor code --- internal/rpc/group/group.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 6fb8318d4..9df6064f6 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -78,9 +78,10 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR //Time stamp + MD5 to generate group chat id groupId := utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10)) //to group - groupInfo := db.Group{GroupID: groupId} + groupInfo := db.Group{} utils.CopyStructFields(&groupInfo, req.GroupInfo) groupInfo.CreatorUserID = req.OpUserID + groupInfo.GroupID = groupId err := imdb.InsertIntoGroup(groupInfo) if err != nil { log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo) From 7f00a3075fdef633615549e1f93a8ff67667859a Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Wed, 19 Jan 2022 09:32:46 +0800 Subject: [PATCH 8/9] Refactor code --- pkg/base_info/group_api_struct.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/base_info/group_api_struct.go b/pkg/base_info/group_api_struct.go index 9847ef1c5..dec18fc0b 100644 --- a/pkg/base_info/group_api_struct.go +++ b/pkg/base_info/group_api_struct.go @@ -1,7 +1,6 @@ package base_info import ( - "Open_IM/pkg/common/db" open_im_sdk "Open_IM/pkg/proto/sdk_ws" ) @@ -143,8 +142,13 @@ type QuitGroupResp struct { } type SetGroupInfoReq struct { - db.Group - OperationID string `json:"operationID" binding:"required"` + GroupID string `json:"groupID" binding:"required"` + GroupName string `json:"groupName"` + Notification string `json:"notification"` + Introduction string `json:"introduction"` + FaceURL string `json:"faceURL"` + Ex string `json:"ex"` + OperationID string `json:"operationID" binding:"required"` } type SetGroupInfoResp struct { CommResp From 83e842d121fcd907e6555fbca2afea9d55f52478 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Wed, 19 Jan 2022 09:33:31 +0800 Subject: [PATCH 9/9] Refactor code --- internal/api/group/group.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/api/group/group.go b/internal/api/group/group.go index 85473b4c2..5d2d8405f 100644 --- a/internal/api/group/group.go +++ b/internal/api/group/group.go @@ -450,7 +450,7 @@ func SetGroupInfo(c *gin.Context) { return } req := &rpc.SetGroupInfoReq{GroupInfo: &open_im_sdk.GroupInfo{}} - utils.CopyStructFields(req.GroupInfo, ¶ms.Group) + utils.CopyStructFields(req.GroupInfo, ¶ms) req.OperationID = params.OperationID var ok bool ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))