diff --git a/internal/api/group/group.go b/internal/api/group/group.go index 61bc95495..5d2d8405f 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}) } @@ -257,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) @@ -447,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")) 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/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) diff --git a/pkg/base_info/group_api_struct.go b/pkg/base_info/group_api_struct.go index 01ba3da84..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" ) @@ -90,7 +89,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"` } @@ -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 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"` } diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go index 41347190b..3a26ca88f 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)