feat: sqlite: implement GetUserByEmail
This commit is contained in:
parent
9918c9918f
commit
7c9b7aa154
3 changed files with 61 additions and 4 deletions
|
|
@ -92,3 +92,31 @@ func (s *Store) GetUserByID(ctx context.Context, id string) (*store.User, error)
|
|||
}
|
||||
return &u, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetUserByEmail(ctx context.Context, email string) (*store.User, error) {
|
||||
row := s.db.QueryRowContext(ctx, s.q.GetUserByEmail, email)
|
||||
u, err := s.scanUser(row)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, fmt.Errorf("pase/sqlite: get user by email: %w", store.ErrUserNotFound)
|
||||
}
|
||||
return nil, fmt.Errorf("pase/sqlite: get user by email: %w", err)
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func (s *Store) scanUser(row *sql.Row) (*store.User, error) {
|
||||
var u store.User
|
||||
err := row.Scan(
|
||||
&u.ID, &u.Email, &u.EmailVerifiedAt,
|
||||
&u.Username, &u.UsernameNormalized, &u.DisplayName, &u.ProfileImageURL,
|
||||
&u.Status, &u.StatusReason,
|
||||
&u.StatusChangedAt, &u.StatusExpiresAt,
|
||||
&u.FailedLoginCount, &u.LastFailedLoginAt,
|
||||
&u.CreatedAt, &u.UpdatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &u, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue