activitylog

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package activitylog defines the ActivityLog entity for tracking entity lifecycle events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action describes what happened to the entity.

const (
	ActionCreated Action = "created"
	ActionUpdated Action = "updated"
	ActionDeleted Action = "deleted"
)

type ActivityLog

type ActivityLog struct {
	ID             uuid.UUID      `gorm:"column:id;type:char(36);primaryKey"`
	EntityType     EntityType     `gorm:"column:entity_type;type:varchar(50);not null;index:idx_activity_logs_entity"`
	EntityID       uuid.UUID      `gorm:"column:entity_id;type:char(36);not null;index:idx_activity_logs_entity"`
	ActorID        uuid.UUID      `gorm:"column:actor_id;type:char(36);not null;index:idx_activity_logs_actor"`
	ActorType      ActorType      `gorm:"column:actor_type;type:varchar(20);not null;index:idx_activity_logs_actor"`
	Action         Action         `gorm:"column:action;type:varchar(50);not null"`
	Changes        datatypes.JSON `gorm:"column:changes;type:jsonb"`
	EntitySnapshot datatypes.JSON `gorm:"column:entity_snapshot;type:jsonb"`
	Metadata       datatypes.JSON `gorm:"column:metadata;type:jsonb"`
	Message        *string        `gorm:"column:message;type:text"`
	SourceClient   *string        `gorm:"column:source_client;type:text"`
	SourceDetails  *string        `gorm:"column:source_details;type:text"`
	Visibility     Visibility     `gorm:"column:visibility;type:varchar(20);not null"`
	CreatedAt      time.Time      `gorm:"column:created_at;type:timestamp;not null;autoCreateTime:false"`
}

func New

func New(now time.Time, entry *Entry) (*ActivityLog, error)

New constructs an ActivityLog from an entry, marshaling JSON fields.

func (*ActivityLog) TableName

func (*ActivityLog) TableName() string

type ActorType

type ActorType string

ActorType identifies who performed the action.

const (
	ActorTypeUser    ActorType = "user"
	ActorTypeService ActorType = "service"
	ActorTypeAdmin   ActorType = "admin"
)

type EntityType

type EntityType string

EntityType identifies which domain entity the log entry belongs to.

const (
	EntityTypeAsset        EntityType = "asset"
	EntityTypeComment      EntityType = "comment"
	EntityTypeSubscription EntityType = "subscription"
	EntityTypeTransfer     EntityType = "transfer"
)

type Entry

type Entry struct {
	EntityType     EntityType
	EntityID       uuid.UUID
	ActorID        uuid.UUID
	ActorType      ActorType
	Action         Action
	Changes        any
	EntitySnapshot any
	Metadata       any
	Message        *string
	SourceClient   *string
	SourceDetails  *string
	Visibility     Visibility
}

Entry holds all fields for a single activity log record.

type ListFilter

type ListFilter struct {
	EntityType *EntityType
	EntityID   *uuid.UUID
	ActorType  *ActorType
	ActorID    *uuid.UUID
	Visibility *Visibility
	Actions    []Action
	From       *time.Time
	To         *time.Time
	Cursor     *string
	PerPage    int
}

type ListResult

type ListResult struct {
	Items   []*ActivityLog
	Next    *string
	HasMore bool
}

type Repository

type Repository interface {
	Create(ctx context.Context, log *ActivityLog) error
	List(ctx context.Context, filter *ListFilter) (*ListResult, error)
}

type Visibility

type Visibility string

Visibility controls who can read the log entry.

const (
	VisibilityUsersAndAdmins Visibility = "users_and_admins"
	VisibilityAdminsOnly     Visibility = "admins_only"
)

Jump to

Keyboard shortcuts

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