refactor: use helper function to scan user in GetUserByID
This commit is contained in:
parent
7c9b7aa154
commit
418aeb5f6c
1 changed files with 2 additions and 10 deletions
|
|
@ -75,22 +75,14 @@ func (s *Store) CreateUser(ctx context.Context, u *store.User) error {
|
||||||
func (s *Store) GetUserByID(ctx context.Context, id string) (*store.User, error) {
|
func (s *Store) GetUserByID(ctx context.Context, id string) (*store.User, error) {
|
||||||
row := s.db.QueryRowContext(ctx, s.q.GetUserByID, id)
|
row := s.db.QueryRowContext(ctx, s.q.GetUserByID, id)
|
||||||
|
|
||||||
var u store.User
|
u, err := s.scanUser(row)
|
||||||
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 {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, fmt.Errorf("pase/sqlite: get user by id: %w", store.ErrUserNotFound)
|
return nil, fmt.Errorf("pase/sqlite: get user by id: %w", store.ErrUserNotFound)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("pase/sqlite: get user by id: %w", err)
|
return nil, fmt.Errorf("pase/sqlite: get user by id: %w", err)
|
||||||
}
|
}
|
||||||
return &u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetUserByEmail(ctx context.Context, email string) (*store.User, error) {
|
func (s *Store) GetUserByEmail(ctx context.Context, email string) (*store.User, error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue