domain

package
v0.0.0-...-dc7611c Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateDataModel

type AggregateDataModel struct {
	*EntityDataModel
	OriginalVersion int64 `json:"originalVersion" bson:"originalVersion,omitempty"`
}

type AggregateRoot

type AggregateRoot struct {
	*Entity
	// contains filtered or unexported fields
}

AggregateRoot base aggregate contains all main necessary fields

func NewAggregateRoot

func NewAggregateRoot(aggregateType string) *AggregateRoot

func NewAggregateRootWithId

func NewAggregateRootWithId(id uuid.UUID, aggregateType string) *AggregateRoot

func (*AggregateRoot) AddDomainEvent

func (a *AggregateRoot) AddDomainEvent(event IDomainEvent) error

func (*AggregateRoot) AddDomainEvents

func (a *AggregateRoot) AddDomainEvents(event IDomainEvent)

func (*AggregateRoot) GetUncommittedEvents

func (a *AggregateRoot) GetUncommittedEvents() []IDomainEvent

GetUncommittedEvents get AggregateRoot uncommitted domain_events events

func (*AggregateRoot) HasUncommittedEvents

func (a *AggregateRoot) HasUncommittedEvents() bool

HasUncommittedEvents returns true if AggregateRoot has uncommitted domain_events events

func (*AggregateRoot) MarkUncommittedEventAsCommitted

func (a *AggregateRoot) MarkUncommittedEventAsCommitted()

MarkUncommittedEventAsCommitted clear AggregateRoot uncommitted domain_events events

func (*AggregateRoot) OriginalVersion

func (a *AggregateRoot) OriginalVersion() int64

func (*AggregateRoot) String

func (a *AggregateRoot) String() string

type DomainEvent

type DomainEvent struct {
	*events.Event
	AggregateId             uuid.UUID `json:"aggregate_id"`
	AggregateSequenceNumber int64     `json:"aggregate_sequence_number"`
}

func NewDomainEvent

func NewDomainEvent(eventType string) *DomainEvent

func (*DomainEvent) GetAggregateId

func (d *DomainEvent) GetAggregateId() uuid.UUID

func (*DomainEvent) GetAggregateSequenceNumber

func (d *DomainEvent) GetAggregateSequenceNumber() int64

func (*DomainEvent) WithAggregate

func (d *DomainEvent) WithAggregate(
	aggregateId uuid.UUID,
	aggregateSequenceNumber int64,
) *DomainEvent

type Entity

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

func NewEntity

func NewEntity(entityType string) *Entity

NewEntity creates a new Entity

func NewEntityWithId

func NewEntityWithId(id uuid.UUID, entityType string) *Entity

NewEntityWithId creates a new Entity with an id

func (*Entity) CreatedAt

func (e *Entity) CreatedAt() time.Time

func (*Entity) EntityType

func (e *Entity) EntityType() string

func (*Entity) Id

func (e *Entity) Id() uuid.UUID

func (*Entity) SetEntityType

func (e *Entity) SetEntityType(entityType string)

func (*Entity) SetId

func (e *Entity) SetId(id uuid.UUID)

func (*Entity) SetUpdatedAt

func (e *Entity) SetUpdatedAt(updatedAt time.Time)

func (*Entity) UpdatedAt

func (e *Entity) UpdatedAt() time.Time

type EntityDataModel

type EntityDataModel struct {
	Id         uuid.UUID `json:"id"          bson:"id,omitempty"`
	EntityType string    `json:"entity_type" bson:"entity_type,omitempty"`
	CreatedAt  time.Time `json:"created_at"  bson:"created_at,omitempty"`
	UpdatedAt  time.Time `json:"updated_at"  bson:"updated_at"`
}

type EventEnvelope

type EventEnvelope struct {
	EventData interface{}
	Metadata  metadata.Metadata
}

type IAggregateRoot

type IAggregateRoot interface {
	IEntity

	// OriginalVersion Gets the original version is the aggregate version we got from the store. This is used to ensure optimistic concurrency,
	// to check if there were no changes made to the aggregate state between load and save for the current operation.
	OriginalVersion() int64

	// AddDomainEvents adds a new domain_events event to the aggregate's uncommitted events.
	AddDomainEvents(event IDomainEvent) error

	// MarkUncommittedEventAsCommitted Mark all changes (events) as committed, clears uncommitted changes and updates the current version of the aggregate.
	MarkUncommittedEventAsCommitted()

	// HasUncommittedEvents Does the aggregate have change that have not been committed to storage
	HasUncommittedEvents() bool

	// GetUncommittedEvents Gets a list of uncommitted events for this aggregate.
	GetUncommittedEvents() []IDomainEvent

	// String Returns a string representation of the aggregate.
	String() string
}

type IDomainEvent

type IDomainEvent interface {
	events.IEvent
	GetAggregateId() uuid.UUID
	GetAggregateSequenceNumber() int64
	WithAggregate(aggregateId uuid.UUID, aggregateSequenceNumber int64) *DomainEvent
}

type IEntity

type IEntity interface {
	Id() uuid.UUID
	CreatedAt() time.Time
	UpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time)
	SetEntityType(entityType string)
	SetId(id uuid.UUID)
}

Jump to

Keyboard shortcuts

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