Skip to content

Commit

Permalink
Merge branch 'demo' of github.com:wangzijian2002/LinkMe into demo
Browse files Browse the repository at this point in the history
完善互动信息接口
  • Loading branch information
GoSimplicity committed May 28, 2024
2 parents a74b20b + e2233d5 commit 2a52293
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions internal/repository/dao/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type UserDAO interface {
CreateUser(ctx context.Context, u User) error
FindByID(ctx context.Context, id int64) (User, error)
FindByEmail(ctx context.Context, email string) (User, error)
FindByPhone(ctx context.Context, phone string) (User, error)
}

type userDAO struct {
Expand Down Expand Up @@ -76,3 +77,16 @@ func (ud *userDAO) FindByEmail(ctx context.Context, email string) (User, error)
}
return user, nil
}

// FindByPhone 根据phone查询用户信息
func (ud *userDAO) FindByPhone(ctx context.Context, phone string) (User, error) {
var user User
err := ud.db.WithContext(ctx).Where("phone = ?", phone).First(&user).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return User{}, ErrUserNotFound
}
return User{}, err
}
return user, nil
}
4 changes: 2 additions & 2 deletions internal/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (ur *userRepository) FindByID(ctx context.Context, id int64) (domain.User,

// FindByPhone 通过电话查询用户
func (ur *userRepository) FindByPhone(ctx context.Context, phone string) (domain.User, error) {
//TODO implement me
panic("implement me")
u, err := ur.dao.FindByEmail(ctx, phone)
return toDomainUser(u), err
}

// FindByEmail 通过Email查询用户
Expand Down

0 comments on commit 2a52293

Please sign in to comment.