Record project continuation changes
This commit is contained in:
@@ -70,7 +70,7 @@ type postgresInstallationRepository struct {
|
||||
|
||||
func (r *postgresUserRepository) GetByEmail(ctx context.Context, email string) (*User, error) {
|
||||
const query = `
|
||||
SELECT id::text, email, password_hash, mfa_enabled, created_at, updated_at
|
||||
SELECT id::text, email, password_hash, mfa_enabled, platform_role, created_at, updated_at
|
||||
FROM users
|
||||
WHERE email = $1
|
||||
`
|
||||
@@ -79,13 +79,53 @@ WHERE email = $1
|
||||
|
||||
func (r *postgresUserRepository) GetByID(ctx context.Context, userID string) (*User, error) {
|
||||
const query = `
|
||||
SELECT id::text, email, password_hash, mfa_enabled, created_at, updated_at
|
||||
SELECT id::text, email, password_hash, mfa_enabled, platform_role, created_at, updated_at
|
||||
FROM users
|
||||
WHERE id = $1::uuid
|
||||
`
|
||||
return scanOptionalUser(r.db.QueryRow(ctx, query, userID))
|
||||
}
|
||||
|
||||
func (r *postgresUserRepository) List(ctx context.Context) ([]User, error) {
|
||||
const query = `
|
||||
SELECT id::text, email, password_hash, mfa_enabled, platform_role, created_at, updated_at
|
||||
FROM users
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
rows, err := r.db.Query(ctx, query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query users: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
var users []User
|
||||
for rows.Next() {
|
||||
user, err := scanOptionalUser(rows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user != nil {
|
||||
users = append(users, *user)
|
||||
}
|
||||
}
|
||||
return users, rows.Err()
|
||||
}
|
||||
|
||||
func (r *postgresUserRepository) Create(ctx context.Context, user User) (*User, error) {
|
||||
const query = `
|
||||
INSERT INTO users (email, password_hash, mfa_enabled, platform_role, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id::text, email, password_hash, mfa_enabled, platform_role, created_at, updated_at
|
||||
`
|
||||
return scanOptionalUser(r.db.QueryRow(ctx, query,
|
||||
user.Email,
|
||||
user.PasswordHash,
|
||||
user.MFAEnabled,
|
||||
user.PlatformRole,
|
||||
user.CreatedAt,
|
||||
user.UpdatedAt,
|
||||
))
|
||||
}
|
||||
|
||||
func (r *postgresDeviceRepository) Upsert(ctx context.Context, params UpsertDeviceParams) (*Device, error) {
|
||||
const query = `
|
||||
INSERT INTO devices (
|
||||
@@ -348,7 +388,7 @@ ON CONFLICT (email) DO UPDATE SET
|
||||
password_hash = EXCLUDED.password_hash,
|
||||
platform_role = EXCLUDED.platform_role,
|
||||
updated_at = EXCLUDED.updated_at
|
||||
RETURNING id::text, email, password_hash, mfa_enabled, created_at, updated_at
|
||||
RETURNING id::text, email, password_hash, mfa_enabled, platform_role, created_at, updated_at
|
||||
`, email, params.PasswordHash, params.Role, now))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("upsert bootstrap owner: %w", err)
|
||||
@@ -461,6 +501,7 @@ func scanOptionalUser(row scanner) (*User, error) {
|
||||
&user.Email,
|
||||
&user.PasswordHash,
|
||||
&user.MFAEnabled,
|
||||
&user.PlatformRole,
|
||||
&user.CreatedAt,
|
||||
&user.UpdatedAt,
|
||||
); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user