add login route

This commit is contained in:
2026-07-02 03:30:51 +07:00
parent d22ad7cb09
commit 20ada8caa2
9 changed files with 389 additions and 12 deletions
+32
View File
@@ -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
}