Error code standardization

This commit is contained in:
skiffer-git 2023-02-01 17:54:16 +08:00
parent a5a1cbb077
commit 6658566144
3 changed files with 20 additions and 23 deletions

View File

@ -4,7 +4,7 @@ import (
"Open_IM/internal/common/check"
"Open_IM/internal/common/convert"
chat "Open_IM/internal/rpc/msg"
"Open_IM/pkg/common/db/relation"
"Open_IM/pkg/common/db/table"
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/common/tracelog"
pbFriend "Open_IM/pkg/proto/friend"
@ -20,15 +20,11 @@ func (s *friendServer) GetBlacks(ctx context.Context, req *pbFriend.GetBlacksReq
if err != nil {
return nil, err
}
blackIDList := make([]string, 0, len(blacks))
for _, black := range blacks {
b, err := convert.NewDBBlack(black).Convert()
resp.Blacks, err = (*convert.DBBlack)(nil).DB2PB(blacks)
if err != nil {
return nil, err
}
resp.Blacks = append(resp.Blacks, b)
blackIDList = append(blackIDList, black.BlockUserID)
}
resp.Total = int32(total)
return resp, nil
}
@ -49,10 +45,10 @@ func (s *friendServer) RemoveBlack(ctx context.Context, req *pbFriend.RemoveBlac
if err := check.Access(ctx, req.OwnerUserID); err != nil {
return nil, err
}
if err := s.BlackInterface.Delete(ctx, []*relation.Black{{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID}}); err != nil {
if err := s.BlackInterface.Delete(ctx, []*table.BlackModel{{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID}}); err != nil {
return nil, err
}
chat.BlackDeletedNotification(req)
chat.BlackDeletedNotification(ctx, req)
return resp, nil
}
@ -61,10 +57,10 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbFriend.AddBlackReq)
if err := token_verify.CheckAccessV3(ctx, req.OwnerUserID); err != nil {
return nil, err
}
black := relation.Black{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID, OperatorUserID: tracelog.GetOpUserID(ctx)}
if err := s.BlackInterface.Create(ctx, []*relation.Black{&black}); err != nil {
black := table.BlackModel{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID, OperatorUserID: tracelog.GetOpUserID(ctx)}
if err := s.BlackInterface.Create(ctx, []*table.BlackModel{&black}); err != nil {
return nil, err
}
chat.BlackAddedNotification(tracelog.GetOperationID(ctx), req)
chat.BlackAddedNotification(ctx, req)
return resp, nil
}

View File

@ -7,6 +7,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/controller"
"Open_IM/pkg/common/db/relation"
"Open_IM/pkg/common/db/table"
"Open_IM/pkg/common/log"
promePkg "Open_IM/pkg/common/prometheus"
"Open_IM/pkg/common/token_verify"
@ -197,7 +198,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
if err != nil {
return nil, err
}
err = s.Update(ctx, []*relation.User{user})
err = s.Update(ctx, []*table.UserModel{user})
if err != nil {
return nil, err
}
@ -213,11 +214,11 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
}
go func() {
for _, v := range rpcResp.FriendsInfo {
chat.FriendInfoUpdatedNotification(tracelog.GetOperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, tracelog.GetOpUserID(ctx))
chat.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, v.FriendUser.UserID, tracelog.GetOpUserID(ctx))
}
}()
chat.UserInfoUpdatedNotification(tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx), req.UserInfo.UserID)
chat.UserInfoUpdatedNotification(ctx, tracelog.GetOpUserID(ctx), req.UserInfo.UserID)
if req.UserInfo.FaceURL != "" {
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx))
}
@ -235,13 +236,13 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se
if err != nil {
return nil, err
}
chat.UserInfoUpdatedNotification(tracelog.GetOperationID(ctx), req.UserID, req.UserID)
chat.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID)
return &resp, nil
}
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
resp := pbUser.AccountCheckResp{}
err := token_verify.CheckManagerUserID(ctx, tracelog.GetOpUserID(ctx))
err := token_verify.CheckAdmin(ctx)
if err != nil {
return nil, err
}

View File

@ -1,7 +1,7 @@
package controller
import (
"Open_IM/pkg/common/db/relation"
"Open_IM/pkg/common/db/table"
"context"
"errors"
"gorm.io/gorm"
@ -9,11 +9,11 @@ import (
type BlackInterface interface {
// Create 增加黑名单
Create(ctx context.Context, blacks []*relation.Black) (err error)
Create(ctx context.Context, blacks []*table.BlackModel) (err error)
// Delete 删除黑名单
Delete(ctx context.Context, blacks []*relation.Black) (err error)
Delete(ctx context.Context, blacks []*table.BlackModel) (err error)
// FindOwnerBlacks 获取黑名单列表
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*table.BlackModel, total int64, err error)
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
}