preferences

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 10 Imported by: 3

Documentation

Overview

Package preferences stores scoped user preference records and exposes helpers to resolve effective settings using go-options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToPreferenceRecord

func ToPreferenceRecord(record *Record) types.PreferenceRecord

ToPreferenceRecord converts the Bun model into the domain preference record.

Types

type Record

type Record struct {
	bun.BaseModel `bun:"table:user_preferences"`

	ID         uuid.UUID      `bun:"id,pk,type:uuid"`
	UserID     uuid.UUID      `bun:"user_id,type:uuid"`
	TenantID   uuid.UUID      `bun:"tenant_id,type:uuid"`
	OrgID      uuid.UUID      `bun:"org_id,type:uuid"`
	ScopeLevel string         `bun:"scope_level"`
	Key        string         `bun:"key"`
	Value      map[string]any `bun:"value,type:jsonb"`
	Version    int            `bun:"version"`
	CreatedAt  time.Time      `bun:"created_at"`
	CreatedBy  uuid.UUID      `bun:"created_by,type:uuid"`
	UpdatedAt  time.Time      `bun:"updated_at"`
	UpdatedBy  uuid.UUID      `bun:"updated_by,type:uuid"`
}

Record models the user_preferences row.

func FromPreferenceRecord

func FromPreferenceRecord(record types.PreferenceRecord) *Record

FromPreferenceRecord converts a domain preference record into the Bun model.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository implements types.PreferenceRepository.

func NewRepository

func NewRepository(cfg RepositoryConfig) (*Repository, error)

NewRepository constructs the default preference repository.

func (*Repository) DeletePreference

func (r *Repository) DeletePreference(ctx context.Context, userID uuid.UUID, scope types.ScopeFilter, level types.PreferenceLevel, key string) error

DeletePreference removes a scoped preference entry.

func (*Repository) ListPreferences

func (r *Repository) ListPreferences(ctx context.Context, filter types.PreferenceFilter) ([]types.PreferenceRecord, error)

ListPreferences fetches preference records for the requested scope level.

func (*Repository) UpsertPreference

func (r *Repository) UpsertPreference(ctx context.Context, record types.PreferenceRecord) (*types.PreferenceRecord, error)

UpsertPreference inserts or updates a scoped preference entry.

type RepositoryConfig

type RepositoryConfig struct {
	DB         *bun.DB
	Repository repository.Repository[*Record]
	Clock      types.Clock
	IDGen      types.IDGenerator
}

RepositoryConfig wires dependencies for the Bun-backed preference store.

type ResolveInput

type ResolveInput struct {
	UserID uuid.UUID
	Scope  types.ScopeFilter
	Levels []types.PreferenceLevel
	Keys   []string
	Base   map[string]any
}

ResolveInput controls which scopes participate in the resolution process.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver merges scoped preference layers via go-options.

func NewResolver

func NewResolver(cfg ResolverConfig) (*Resolver, error)

NewResolver constructs a preference resolver.

func (*Resolver) Resolve

Resolve builds the effective preference snapshot for the supplied scope chain.

type ResolverConfig

type ResolverConfig struct {
	Repository types.PreferenceRepository
	Defaults   map[string]any
}

ResolverConfig wires dependencies for the preference resolver.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL