Chore: Add user service method GetByEmail (#53298)
This commit is contained in:
@@ -62,6 +62,10 @@ type GetUserByLoginQuery struct {
|
||||
LoginOrEmail string
|
||||
}
|
||||
|
||||
type GetUserByEmailQuery struct {
|
||||
Email string
|
||||
}
|
||||
|
||||
func (u *User) NameOrFallback() string {
|
||||
if u.Name != "" {
|
||||
return u.Name
|
||||
|
||||
@@ -9,4 +9,5 @@ type Service interface {
|
||||
Delete(context.Context, *DeleteUserCommand) error
|
||||
GetByID(context.Context, *GetUserByIDQuery) (*User, error)
|
||||
GetByLogin(context.Context, *GetUserByLoginQuery) (*User, error)
|
||||
GetByEmail(context.Context, *GetUserByEmailQuery) (*User, error)
|
||||
}
|
||||
|
||||
@@ -257,3 +257,13 @@ func (s *Service) GetByLogin(ctx context.Context, query *user.GetUserByLoginQuer
|
||||
}
|
||||
return q.Result, nil
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error) {
|
||||
q := models.GetUserByEmailQuery{Email: query.Email}
|
||||
err := s.sqlStore.GetUserByEmail(ctx, &q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return q.Result, nil
|
||||
}
|
||||
|
||||
@@ -30,3 +30,7 @@ func (f *FakeUserService) GetByID(ctx context.Context, query *user.GetUserByIDQu
|
||||
func (f *FakeUserService) GetByLogin(ctx context.Context, query *user.GetUserByLoginQuery) (*user.User, error) {
|
||||
return f.ExpectedUser, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error) {
|
||||
return f.ExpectedUser, f.ExpectedError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user