Chore: Add user service method GetByEmail (#53298)

This commit is contained in:
idafurjes 2022-08-04 13:47:30 +02:00 committed by GitHub
parent 1ecbe22751
commit af83a09a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 8 deletions

View File

@ -244,12 +244,13 @@ func (s *AuthInfoStore) GetUserByLogin(ctx context.Context, login string) (*user
}
func (s *AuthInfoStore) GetUserByEmail(ctx context.Context, email string) (*user.User, error) {
query := models.GetUserByEmailQuery{Email: email}
if err := s.sqlStore.GetUserByEmail(ctx, &query); err != nil {
query := user.GetUserByEmailQuery{Email: email}
usr, err := s.userService.GetByEmail(ctx, &query)
if err != nil {
return nil, err
}
return query.Result, nil
return usr, nil
}
// decodeAndDecrypt will decode the string with the standard base64 decoder and then decrypt it

View File

@ -137,10 +137,6 @@ func (m *SQLStoreMock) CreateUser(ctx context.Context, cmd user.CreateUserComman
return nil, m.ExpectedError
}
func (m *SQLStoreMock) GetUserByEmail(ctx context.Context, query *models.GetUserByEmailQuery) error {
return m.ExpectedError
}
func (m *SQLStoreMock) UpdateUser(ctx context.Context, cmd *models.UpdateUserCommand) error {
return m.ExpectedError
}

View File

@ -31,7 +31,6 @@ type Store interface {
GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error
DeleteOldLoginAttempts(ctx context.Context, cmd *models.DeleteOldLoginAttemptsCommand) error
CreateUser(ctx context.Context, cmd user.CreateUserCommand) (*user.User, error)
GetUserByEmail(ctx context.Context, query *models.GetUserByEmailQuery) error
UpdateUser(ctx context.Context, cmd *models.UpdateUserCommand) error
ChangeUserPassword(ctx context.Context, cmd *models.ChangeUserPasswordCommand) error
UpdateUserLastSeenAt(ctx context.Context, cmd *models.UpdateUserLastSeenAtCommand) error

View File

@ -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

View File

@ -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)
}

View File

@ -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
}

View File

@ -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
}