Refactor code

pull/131/head
wenxu12345 3 years ago
parent 2f62339f0c
commit 8b1a7def38

@ -146,7 +146,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
utils.CopyStructFields(&friendRequest, req.CommID)
// {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }]
log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)
err := imdb.UpdateFriendApplication(&friendRequest)
err := imdb.InsertFriendApplication(&friendRequest)
if err != nil {
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil

@ -95,7 +95,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
}
//to group member
groupMember := imdb.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner}
groupMember := imdb.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID}
utils.CopyStructFields(&groupMember, us)
err = im_mysql_model.InsertIntoGroupMember(groupMember)
if err != nil {

@ -66,12 +66,9 @@ func UpdateFriendApplication(friendRequest *FriendRequest) error {
return err
}
friendRequest.CreateTime = time.Now()
if dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?",
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).RowsAffected == 0 {
return InsertFriendApplication(friendRequest)
} else {
return nil
}
return dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?",
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
}
func InsertFriendApplication(friendRequest *FriendRequest) error {

Loading…
Cancel
Save