mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 03:26:57 +08:00
Refactor code
This commit is contained in:
parent
9b76407193
commit
7e88621aa1
@ -288,7 +288,6 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
|||||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := imdb.DeleteSingleFriendInfo(req.CommID.FromUserID, req.CommID.ToUserID)
|
err := imdb.DeleteSingleFriendInfo(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.CommID.OperationID, "DeleteSingleFriendInfo failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
|
log.NewError(req.CommID.OperationID, "DeleteSingleFriendInfo failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
|
||||||
|
@ -14,10 +14,10 @@ import "time"
|
|||||||
//}
|
//}
|
||||||
//open_im_sdk.FriendInfo(FriendUser) != imdb.Friend(FriendUserID)
|
//open_im_sdk.FriendInfo(FriendUser) != imdb.Friend(FriendUserID)
|
||||||
type Friend struct {
|
type Friend struct {
|
||||||
OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
|
OwnerUserID string `gorm:"column:owner_user_id;primary_key;"`
|
||||||
Remark string `gorm:"column:remark"`
|
Remark string `gorm:"column:remark"`
|
||||||
CreateTime time.Time `gorm:"column:create_time"`
|
CreateTime time.Time `gorm:"column:create_time"`
|
||||||
FriendUserID string `gorm:"column:friend_user_id;primaryKey;"`
|
FriendUserID string `gorm:"column:friend_user_id;primary_key;"`
|
||||||
AddSource int32 `gorm:"column:add_source"`
|
AddSource int32 `gorm:"column:add_source"`
|
||||||
OperatorUserID string `gorm:"column:operator_user_id"`
|
OperatorUserID string `gorm:"column:operator_user_id"`
|
||||||
Ex string `gorm:"column:ex"`
|
Ex string `gorm:"column:ex"`
|
||||||
@ -159,7 +159,7 @@ type User struct {
|
|||||||
//}
|
//}
|
||||||
// open_im_sdk.BlackInfo(BlackUserInfo) != imdb.Black (BlockUserID)
|
// open_im_sdk.BlackInfo(BlackUserInfo) != imdb.Black (BlockUserID)
|
||||||
type Black struct {
|
type Black struct {
|
||||||
OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
|
OwnerUserID string `gorm:"column:owner_user_id;primaryKey;size:256"`
|
||||||
CreateTime time.Time `gorm:"column:create_time"`
|
CreateTime time.Time `gorm:"column:create_time"`
|
||||||
BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
|
BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
|
||||||
AddSource int32 `gorm:"column:add_source"`
|
AddSource int32 `gorm:"column:add_source"`
|
||||||
|
@ -39,7 +39,10 @@ func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var friends []db.Friend
|
var friends []db.Friend
|
||||||
|
var x db.Friend
|
||||||
|
x.OwnerUserID = OwnerUserID
|
||||||
err = dbConn.Table("friend").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
|
err = dbConn.Table("friend").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,25 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// copy a by b b->a
|
// copy a by b b->a
|
||||||
func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error) {
|
func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error) {
|
||||||
return copier.Copy(a, b)
|
return copier.Copy(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Wrap(err error, message string) error {
|
||||||
|
return errors.Wrap(err, "==> "+printCallerNameAndLine()+message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithMessage(err error, message string) error {
|
||||||
|
return errors.WithMessage(err, "==> "+printCallerNameAndLine()+message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func printCallerNameAndLine() string {
|
||||||
|
pc, _, line, _ := runtime.Caller(2)
|
||||||
|
return runtime.FuncForPC(pc).Name() + "()@" + strconv.Itoa(line) + ": "
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user