소스 검색

update

master
DengBiao 2 년 전
부모
커밋
0bd2c2c3ad
7개의 변경된 파일16개의 추가작업 그리고 15개의 파일을 삭제
  1. +1
    -1
      internal/business/api/business_ext.go
  2. +2
    -2
      internal/business/app/user_app.go
  3. +4
    -4
      internal/business/domain/user/repo/user_dao.go
  4. +2
    -2
      internal/business/domain/user/repo/user_dao_test.go
  5. +4
    -4
      internal/business/domain/user/repo/user_repo.go
  6. +1
    -1
      internal/business/domain/user/service/auth.go
  7. +2
    -1
      pkg/pb/business.ext.pb.go

+ 1
- 1
internal/business/api/business_ext.go 파일 보기

@@ -42,6 +42,6 @@ func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserRe
}

func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
users, err := app.UserApp.Search(ctx, req.Key)
users, err := app.UserApp.Search(ctx, req.Key, req.MasterId)
return &pb.SearchUserResp{Users: users}, err
}

+ 2
- 2
internal/business/app/user_app.go 파일 보기

@@ -51,8 +51,8 @@ func (*userApp) GetByIds(ctx context.Context, userIds []int64) (map[int64]*pb.Us
return pbUsers, nil
}

func (*userApp) Search(ctx context.Context, key string) ([]*pb.User, error) {
users, err := repo.UserRepo.Search(key)
func (*userApp) Search(ctx context.Context, key string, masterId int) ([]*pb.User, error) {
users, err := repo.UserRepo.Search(key, masterId)
if err != nil {
return nil, err
}


+ 4
- 4
internal/business/domain/user/repo/user_dao.go 파일 보기

@@ -47,9 +47,9 @@ func (*userDao) Save(user *model.User) error {
}

// GetByPhoneNumber 根据手机号获取用户信息
func (*userDao) GetByPhoneNumber(phoneNumber string) (*model.User, error) {
func (*userDao) GetByPhoneNumber(phoneNumber string, masterId int) (*model.User, error) {
var user model.User
err := db.DB.First(&user, "phone_number = ?", phoneNumber).Error
err := db.DB.First(&user, "phone_number = ? and master_id = ?", phoneNumber, masterId).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, gerrors.WrapError(err)
}
@@ -70,10 +70,10 @@ func (*userDao) GetByIds(userIds []int64) ([]model.User, error) {
}

// Search 查询用户,这里简单实现,生产环境建议使用ES
func (*userDao) Search(key string) ([]model.User, error) {
func (*userDao) Search(key string, masterId int) ([]model.User, error) {
var users []model.User
key = "%" + key + "%"
err := db.DB.Where("phone_number like ? or nickname like ?", key, key).Find(&users).Error
err := db.DB.Where("phone_number like ? or nickname like ? and master_id = ?", key, key, masterId).Find(&users).Error
if err != nil {
return nil, gerrors.WrapError(err)
}


+ 2
- 2
internal/business/domain/user/repo/user_dao_test.go 파일 보기

@@ -34,11 +34,11 @@ func TestUserDao_GetByIds(t *testing.T) {
}

func TestUserDao_GetByPhoneNumber(t *testing.T) {
user, err := UserDao.GetByPhoneNumber("18829291351")
user, err := UserDao.GetByPhoneNumber("18829291351", 123456)
fmt.Printf("%+v\n %+v\n ", user, err)
}

func TestUserDao_Search(t *testing.T) {
users, err := UserDao.Search("18229")
users, err := UserDao.Search("18229", 123456)
fmt.Printf("%+v\n %+v\n ", users, err)
}

+ 4
- 4
internal/business/domain/user/repo/user_repo.go 파일 보기

@@ -32,8 +32,8 @@ func (*userRepo) Get(userId int64) (*model.User, error) {
return user, err
}

func (*userRepo) GetByPhoneNumber(phoneNumber string) (*model.User, error) {
return UserDao.GetByPhoneNumber(phoneNumber)
func (*userRepo) GetByPhoneNumber(phoneNumber string, masterId int) (*model.User, error) {
return UserDao.GetByPhoneNumber(phoneNumber, masterId)
}

// GetByIds 获取多个用户
@@ -42,8 +42,8 @@ func (*userRepo) GetByIds(userIds []int64) ([]model.User, error) {
}

// Search 搜索用户
func (*userRepo) Search(key string) ([]model.User, error) {
return UserDao.Search(key)
func (*userRepo) Search(key string, masterId int) ([]model.User, error) {
return UserDao.Search(key, masterId)
}

// Save 保存用户


+ 1
- 1
internal/business/domain/user/service/auth.go 파일 보기

@@ -21,7 +21,7 @@ func (*authService) SignIn(ctx context.Context, phoneNumber, code string, master
return false, 0, "", 0, gerrors.ErrBadCode
}

user, err := repo.UserRepo.GetByPhoneNumber(phoneNumber)
user, err := repo.UserRepo.GetByPhoneNumber(phoneNumber, masterId)
if err != nil {
return false, 0, "", 0, err
}


+ 2
- 1
pkg/pb/business.ext.pb.go 파일 보기

@@ -432,7 +432,8 @@ type SearchUserReq struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields

Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
MasterId int `protobuf:"varint,2,opt,name=master_id,json=masterId,proto3" json:"master_id,omitempty"` // 站长id
}

func (x *SearchUserReq) Reset() {


불러오는 중...
취소
저장