chore: establish local platform baseline
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package deviceauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
var ErrDeviceNotFound = errors.New("device identity was not found")
|
||||
|
||||
type Repository struct{ pool *pgxpool.Pool }
|
||||
|
||||
func NewRepository(pool *pgxpool.Pool) *Repository { return &Repository{pool: pool} }
|
||||
|
||||
func (r *Repository) FindByPublicID(ctx context.Context, publicID string) (Identity, error) {
|
||||
var identity Identity
|
||||
err := r.pool.QueryRow(ctx, `
|
||||
SELECT id::text, public_id::text, tenant_id::text, status, credential_ref
|
||||
FROM device
|
||||
WHERE public_id = $1::uuid`, publicID,
|
||||
).Scan(&identity.ID, &identity.PublicID, &identity.TenantID, &identity.Status, &identity.CredentialRef)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return Identity{}, ErrDeviceNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return Identity{}, fmt.Errorf("find device identity: %w", err)
|
||||
}
|
||||
return identity, nil
|
||||
}
|
||||
Reference in New Issue
Block a user