update refresh

This commit is contained in:
2026-07-06 12:58:27 +07:00
parent e4007eb15a
commit 57687d1d62
15 changed files with 483 additions and 66 deletions
+35 -5
View File
@@ -28,11 +28,11 @@ func (s *UsersRepo) AddUser(
username string,
email string,
passwordHash string,
role string,
roles []string,
) error {
tag, err := s.pool.Exec(
ctx,
`INSERT INTO users (username, email, password_hash, role)
`INSERT INTO users (username, email, password_hash, roles)
SELECT $1, $2, $3, $4
WHERE NOT EXISTS (
SELECT 1 FROM users
@@ -41,7 +41,7 @@ func (s *UsersRepo) AddUser(
username,
email,
passwordHash,
role,
roles,
username,
email,
@@ -85,7 +85,7 @@ func (s *UsersRepo) GetUserByEmail(
user := &repos.User{}
row := s.pool.QueryRow(
ctx,
`SELECT id, username, email, password_hash, role, is_active
`SELECT id, username, email, password_hash, roles, is_active
FROM users
WHERE email = $1`,
email,
@@ -95,7 +95,37 @@ func (s *UsersRepo) GetUserByEmail(
&user.Username,
&user.Email,
&user.PasswordHash,
&user.Role,
&user.Roles,
&user.IsActive,
)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, ErrUserNotFound
}
return nil, err
}
return user, nil
}
func (s *UsersRepo) GetUserByID(
ctx context.Context,
id int,
) (*repos.User, error) {
user := &repos.User{}
row := s.pool.QueryRow(
ctx,
`SELECT id, username, email, password_hash, roles, is_active
FROM users
WHERE id = $1`,
id,
)
err := row.Scan(
&user.ID,
&user.Username,
&user.Email,
&user.PasswordHash,
&user.Roles,
&user.IsActive,
)
if err != nil {