Error code standardization

test-errcode
skiffer-git 2 years ago
parent 12eba46dab
commit f40ae89c8c

@ -5,6 +5,7 @@ import (
"Open_IM/pkg/common/db/table/relation" "Open_IM/pkg/common/db/table/relation"
discoveryRegistry "Open_IM/pkg/discoveryregistry" discoveryRegistry "Open_IM/pkg/discoveryregistry"
sdk "Open_IM/pkg/proto/sdkws" sdk "Open_IM/pkg/proto/sdkws"
utils2 "Open_IM/pkg/utils"
"context" "context"
utils "github.com/OpenIMSDK/open_utils" utils "github.com/OpenIMSDK/open_utils"
"time" "time"
@ -38,13 +39,18 @@ func (*PBFriend) PB2DB(friends []*sdk.FriendInfo) (DBFriends []*relation.FriendM
return return
} }
func (*DBFriend) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, friends []*relation.FriendModel) (PBFriends []*sdk.FriendInfo, err error) { func (db *DBFriend) DB2PB(ctx context.Context, friends []*relation.FriendModel) (PBFriends []*sdk.FriendInfo, err error) {
userIDs := utils2.Slice(friends, func(e *relation.FriendModel) string { return e.FriendUserID })
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
if err != nil {
return nil, err
}
for _, v := range friends { for _, v := range friends {
u, err := NewDBFriend(v, zk).Convert(ctx) pbFriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
if err != nil { utils.CopyStructFields(pbFriend, users[v.OwnerUserID])
return nil, err utils.CopyStructFields(pbFriend.FriendUser, users[v.FriendUserID])
} pbFriend.CreateTime = v.CreateTime.Unix()
PBFriends = append(PBFriends, u) pbFriend.FriendUser.CreateTime = v.CreateTime.Unix()
} }
return return
} }
@ -238,16 +244,16 @@ func (*PBGroup) PB2DB(groups []*sdk.GroupInfo) (DBGroups []*relation.GroupModel,
return return
} }
func (db *DBGroup) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, groups []*relation.GroupModel) (PBGroups []*sdk.GroupInfo, err error) { //func (db *DBGroup) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, groups []*relation.GroupModel) (PBGroups []*sdk.GroupInfo, err error) {
for _, v := range groups { // for _, v := range groups {
u, err := NewDBGroup(v, zk).Convert(ctx) // u, err := NewDBGroup(v, zk).Convert(ctx)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
PBGroups = append(PBGroups, u) // PBGroups = append(PBGroups, u)
} // }
return // return
} //}
func NewDBGroup(groupModel *relation.GroupModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBGroup { func NewDBGroup(groupModel *relation.GroupModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBGroup {
return &DBGroup{GroupModel: groupModel, groupCheck: check.NewGroupChecker(zk)} return &DBGroup{GroupModel: groupModel, groupCheck: check.NewGroupChecker(zk)}
@ -304,16 +310,16 @@ func (*PBGroupMember) PB2DB(groupMembers []*sdk.GroupMemberFullInfo) (DBGroupMem
return return
} }
func (*DBGroupMember) DB2PB(ctx context.Context, groupMembers []*relation.GroupMemberModel) (PBGroupMembers []*sdk.GroupMemberFullInfo, err error) { //func (*DBGroupMember) DB2PB(ctx context.Context, groupMembers []*relation.GroupMemberModel) (PBGroupMembers []*sdk.GroupMemberFullInfo, err error) {
for _, v := range groupMembers { // for _, v := range groupMembers {
u, err := NewDBGroupMember(v).Convert(ctx) // u, err := NewDBGroupMember(v).Convert(ctx)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
PBGroupMembers = append(PBGroupMembers, u) // PBGroupMembers = append(PBGroupMembers, u)
} // }
return // return
} //}
func NewDBGroupMember(groupMember *relation.GroupMemberModel) *DBGroupMember { func NewDBGroupMember(groupMember *relation.GroupMemberModel) *DBGroupMember {
return &DBGroupMember{GroupMemberModel: groupMember} return &DBGroupMember{GroupMemberModel: groupMember}
@ -370,16 +376,16 @@ func (*PBGroupRequest) PB2DB(groupRequests []*sdk.GroupRequest) (DBGroupRequests
return return
} }
func (*DBGroupRequest) DB2PB(groupRequests []*relation.GroupRequestModel) (PBGroupRequests []*sdk.GroupRequest, err error) { //func (*DBGroupRequest) DB2PB(groupRequests []*relation.GroupRequestModel) (PBGroupRequests []*sdk.GroupRequest, err error) {
for _, v := range groupRequests { // for _, v := range groupRequests {
u, err := NewDBGroupRequest(v).Convert() // u, err := NewDBGroupRequest(v).Convert()
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
PBGroupRequests = append(PBGroupRequests, u) // PBGroupRequests = append(PBGroupRequests, u)
} // }
return // return
} //}
func NewDBGroupRequest(groupRequest *relation.GroupRequestModel) *DBGroupRequest { func NewDBGroupRequest(groupRequest *relation.GroupRequestModel) *DBGroupRequest {
return &DBGroupRequest{GroupRequestModel: groupRequest} return &DBGroupRequest{GroupRequestModel: groupRequest}

@ -217,7 +217,7 @@ func (s *friendServer) GetDesignatedFriends(ctx context.Context, req *pbFriend.G
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.FriendsInfo, err = (*convert.DBFriend)(nil).DB2PB(ctx, s.RegisterCenter, friends) resp.FriendsInfo, err = (*convert.NewDBFriend(nil, s.RegisterCenter)).DB2PB(ctx, friends)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -281,7 +281,7 @@ func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbFriend.G
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.FriendsInfo, err = (*convert.DBFriend)(nil).DB2PB(ctx, s.RegisterCenter, friends); err != nil { if resp.FriendsInfo, err = (*convert.NewDBFriend(nil, s.RegisterCenter)).DB2PB(ctx, friends); err != nil {
return nil, err return nil, err
} }
return resp, nil return resp, nil

Loading…
Cancel
Save