models

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package models defines the persisted document shapes for admin-api.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureIndexes

func EnsureIndexes(ctx context.Context) error

EnsureIndexes creates the indexes admin-api relies on: a MongoDB TTL index on expires_at that physically removes expired documents, and a compound index on (scope_type, scope_value) to keep the scoped-query path fast. Safe to call on every startup - CreateOne is idempotent for an identical index definition.

Types

type BannerMessage

type BannerMessage struct {
	ID         primitive.ObjectID `bson:"_id,omitempty" json:"id"`
	ScopeType  ScopeType          `bson:"scope_type" json:"scope_type"`
	ScopeValue string             `bson:"scope_value" json:"scope_value"`
	Severity   Severity           `bson:"severity" json:"severity"`
	Message    string             `bson:"message" json:"message"`
	StartsAt   *time.Time         `bson:"starts_at,omitempty" json:"starts_at,omitempty"`
	ExpiresAt  time.Time          `bson:"expires_at" json:"expires_at"`
	CreatedBy  string             `bson:"created_by" json:"created_by"`
	CreatedAt  time.Time          `bson:"created_at" json:"created_at"`
	UpdatedAt  time.Time          `bson:"updated_at" json:"updated_at"`
}

BannerMessage is the MongoDB document for a platform-wide, service-scoped, or page-scoped admin banner.

func (*BannerMessage) Validate

func (b *BannerMessage) Validate() error

Validate checks that the banner satisfies the invariants required by the spec: a known scope type, a scope value present exactly when the scope requires one, a known severity, a non-empty message, and a required expires_at.

type ScopeType

type ScopeType string

ScopeType identifies what a banner message applies to.

const (
	ScopePlatform ScopeType = "platform"
	ScopeService  ScopeType = "service"
	ScopePage     ScopeType = "page"
)

type Severity

type Severity string

Severity ranks how urgent a banner message is.

const (
	SeverityInfo     Severity = "info"
	SeverityWarning  Severity = "warning"
	SeverityCritical Severity = "critical"
)

func (Severity) Rank

func (s Severity) Rank() int

Rank returns the sort-order weight for this severity (0 = most severe). Unknown severities sort last.

Jump to

Keyboard shortcuts

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