diff --git a/internal/logic/domain/friend/friend_service.go b/internal/logic/domain/friend/friend_service.go index 6fb363f..7bee84d 100644 --- a/internal/logic/domain/friend/friend_service.go +++ b/internal/logic/domain/friend/friend_service.go @@ -67,6 +67,9 @@ func (*friendService) DeleteFriend(ctx context.Context, userId, friendId int64) // AddFriend 添加好友 func (*friendService) AddFriend(ctx context.Context, userId, friendId int64, remarks, description string) error { + if userId == friendId { + return gerrors.ErrNotAllowAddSelf + } masterId, _ := grpclib.GetCtxMasterId(ctx) isAutoAddFriends := svc.SysCfgGet(masterId, "is_auto_add_friends") diff --git a/pkg/gerrors/define.go b/pkg/gerrors/define.go index c4e4faa..129805d 100644 --- a/pkg/gerrors/define.go +++ b/pkg/gerrors/define.go @@ -18,6 +18,7 @@ var ( ErrAlreadyIsFriend = newError(10015, "对方已经是好友了") ErrUserNotFound = newError(10016, "用户找不到") ErrNotIsFriend = newError(10017, "对方暂不是好友") + ErrNotAllowAddSelf = newError(10018, "不允许添加自己为好友") ) func newError(code int, message string) error {