event

package module
v0.0.0-...-3171c24 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const JSON_DB_CONFIG_PATH = "./dbconfig/local_db.json"

Variables

This section is empty.

Functions

func ApplyCommand

func ApplyCommand(command Command, aggregate Aggregate)

func RegisterEvent

func RegisterEvent(event interface{})

func Replay

func Replay(aggregate Aggregate, events []Event)

Types

type Aggregate

type Aggregate interface {
	GetAggregateID() string
	GetVersion() int

	GetChanges() []Event
	MarkAsCommited()
	// contains filtered or unexported methods
}

type BaseAggregate

type BaseAggregate struct {
	UUID         string    `json:"uuid"`
	Version      int       `json:"version"`
	LastModified time.Time `json:"lastModified"`
	Changes      []Event   `json:"changes"`
}

func (*BaseAggregate) GetAggregateID

func (a *BaseAggregate) GetAggregateID() string

func (*BaseAggregate) GetChanges

func (a *BaseAggregate) GetChanges() []Event

func (*BaseAggregate) GetVersion

func (a *BaseAggregate) GetVersion() int

func (*BaseAggregate) MarkAsCommited

func (a *BaseAggregate) MarkAsCommited()

func (*BaseAggregate) UnmarshalJSON

func (a *BaseAggregate) UnmarshalJSON(b []byte) error

type BaseEvent

type BaseEvent interface {
	GetEventType() string
	GetAggregateType() string
	GetCreatedAt() time.Time
	GetSequence() int
	Apply(aggregate Aggregate, event *Event)
}

type Capacity

type Capacity int

Capacity is the capacity in GB available for customers

const (
	//ThreeGB allows 3 GB of capacity
	ThreeGB Capacity = iota
	//SixGB allows 6 GB of capacity
	SixGB Capacity = iota
	//TenGB allows 10 GB of capacity
	TenGB Capacity = iota
)

func (Capacity) String

func (c Capacity) String() string

type Command

type Command interface {
	CreateBaseEvent() BaseEvent
}

type ConfirmOrderCommand

type ConfirmOrderCommand struct {
	ConfirmedBy string
}

func (ConfirmOrderCommand) CreateBaseEvent

func (coc ConfirmOrderCommand) CreateBaseEvent() BaseEvent

type CreateOrderCommand

type CreateOrderCommand struct {
	UUID     string
	Capacity Capacity
}

func (CreateOrderCommand) CreateBaseEvent

func (coc CreateOrderCommand) CreateBaseEvent() BaseEvent

type DbConfig

type DbConfig struct {
	ConnectString string
	DatabaseName  string
	SslMode       string
}

type Event

type Event struct {
	AggregateID   string
	AggregateType string
	EventType     string
	CreatedAt     time.Time
	Sequence      int
	Payload       interface{}
}

func BuildEvent

func BuildEvent(de BaseEvent, aggregateID string) Event

func (Event) ApplyChanges

func (e Event) ApplyChanges(agg Aggregate)

func (*Event) MarshalJSON

func (e *Event) MarshalJSON() (b []byte, err error)

func (Event) Serialize

func (e Event) Serialize() (PersistentEvent, error)

type EventStore

type EventStore struct{}

func (EventStore) CreateSnapshot

func (es EventStore) CreateSnapshot(aggregateid, aggregatestate string, snapshot_event_seq int) error

func (EventStore) EventsForAggregate

func (es EventStore) EventsForAggregate(aggregateid string, eventSeq int) []Event

func (EventStore) GetSnapshot

func (es EventStore) GetSnapshot(aggregateid string) string

func (EventStore) Persist

func (es EventStore) Persist(aggregate Aggregate) error

func (EventStore) PersistEvent

func (es EventStore) PersistEvent(e Event) error

PersistEvent persists an Event in the event store

type Order

type Order struct {
	BaseAggregate
	Capacity    Capacity
	ConfirmedBy string
	RevisedStat RevisedStatus
}

func (*Order) String

func (o *Order) String() string

type OrderConfirmed

type OrderConfirmed struct {
	ConfirmedBy string `json:"confirmedBy"`
}

func (OrderConfirmed) Apply

func (oc OrderConfirmed) Apply(aggregate Aggregate, event *Event)

func (OrderConfirmed) GetAggregateType

func (OrderConfirmed) GetAggregateType() string

func (OrderConfirmed) GetCreatedAt

func (OrderConfirmed) GetCreatedAt() time.Time

func (OrderConfirmed) GetEventType

func (OrderConfirmed) GetEventType() string

func (OrderConfirmed) GetSequence

func (OrderConfirmed) GetSequence() int

type OrderCreated

type OrderCreated struct {
	UUID     string   `json:"uuid"`
	Capacity Capacity `json:"capacity"`
}

func (OrderCreated) Apply

func (oc OrderCreated) Apply(aggregate Aggregate, event *Event)

func (OrderCreated) GetAggregateType

func (OrderCreated) GetAggregateType() string

func (OrderCreated) GetCreatedAt

func (OrderCreated) GetCreatedAt() time.Time

func (OrderCreated) GetEventType

func (OrderCreated) GetEventType() string

func (OrderCreated) GetSequence

func (OrderCreated) GetSequence() int

type OrderRevised

type OrderRevised struct {
	RevisedBy string `json:"revisedBy"`
	Reason    string `json:"reason"`
}

func (OrderRevised) Apply

func (or OrderRevised) Apply(aggregate Aggregate, event *Event)

func (OrderRevised) GetAggregateType

func (OrderRevised) GetAggregateType() string

func (OrderRevised) GetCreatedAt

func (OrderRevised) GetCreatedAt() time.Time

func (OrderRevised) GetEventType

func (OrderRevised) GetEventType() string

func (OrderRevised) GetSequence

func (OrderRevised) GetSequence() int

type PersistentEvent

type PersistentEvent struct {
	AggregateID   string
	AggregateType string
	EventType     string
	CreatedAt     time.Time
	Sequence      int
	RawData       string
}

func (PersistentEvent) Deserialize

func (e PersistentEvent) Deserialize() (Event, error)

type ReviseOrderCommand

type ReviseOrderCommand struct {
	RevisedBy string
	Reason    string
}

func (ReviseOrderCommand) CreateBaseEvent

func (roc ReviseOrderCommand) CreateBaseEvent() BaseEvent

type RevisedStatus

type RevisedStatus struct {
	RevisedBy string
	Reason    string
}

Jump to

Keyboard shortcuts

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