generated from VLADIMIR/template
add login route
This commit is contained in:
@@ -3,7 +3,9 @@ package users_repo
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"evening_detective_server/internal/repos"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
@@ -75,3 +77,33 @@ func (s *UsersRepo) UpdateUserPassword(
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *UsersRepo) GetUserByEmail(
|
||||
ctx context.Context,
|
||||
email string,
|
||||
) (*repos.User, error) {
|
||||
user := &repos.User{}
|
||||
row := s.pool.QueryRow(
|
||||
ctx,
|
||||
`SELECT id, username, email, password_hash, role, is_active
|
||||
FROM users
|
||||
WHERE email = $1`,
|
||||
email,
|
||||
)
|
||||
err := row.Scan(
|
||||
&user.ID,
|
||||
&user.Username,
|
||||
&user.Email,
|
||||
&user.PasswordHash,
|
||||
&user.Role,
|
||||
&user.IsActive,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrUserNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user