userpref

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package userpref owns per-user UI preferences, stored as the JSONB users.preferences column (migration 0040). It is intentionally tiny and schema-agnostic at this layer: Get returns the raw blob, Merge applies a shallow JSON merge. The SET of valid preference keys is governed one layer up by the typed api.UserPreferences contract — this package only guarantees the merge is atomic and scoped to a single, active user.

Spec: system-user-preferences.

Index

Constants

This section is empty.

Variables

View Source
var ErrUserNotFound = errors.New("userpref: user not found")

ErrUserNotFound is returned when the target user id is unknown, soft- deleted, or disabled — the same "no active user" condition the users service guards, kept as a distinct error so the handler maps it to 401.

Functions

This section is empty.

Types

type Service

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

Service reads and merges the users.preferences JSONB column.

func NewService

func NewService(pool *pgxpool.Pool) *Service

NewService binds a Service to a DB pool.

func (*Service) Get

func (s *Service) Get(ctx context.Context, userID uuid.UUID) (json.RawMessage, error)

Get returns the user's stored preferences blob, or `{}` for a user who has never set one (the column defaults to '{}'). ErrUserNotFound for an unknown / soft-deleted user.

func (*Service) Merge

func (s *Service) Merge(ctx context.Context, userID uuid.UUID, patch json.RawMessage) (json.RawMessage, error)

Merge applies a shallow merge of patch onto the user's stored preferences (Postgres `||`: top-level keys in patch overwrite, others are retained) and returns the merged result. A patch of `{}` is a no-op read. ErrUserNotFound for an unknown / soft-deleted user.

patch MUST be a JSON object; the handler validates the key set against the typed contract before calling Merge, so this layer trusts the shape but still defends against a non-object blob.

Jump to

Keyboard shortcuts

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