projection

package
v0.0.3-0...-d907587 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateEventListener

func CreateEventListener(state *State, eventListener *pq.Listener)

CreateEventListener starts a goroutine that listens for event notifications from the database. It parses those events and sends them to the state to be processed.

Types

type State

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

State is the projection of the events into the state of the application.

func NewState

func NewState() *State

NewState returns a new state object to keep track of all aggregates.

func (*State) GetTicket

func (s *State) GetTicket(id TicketID) (*Ticket, bool)

GetTicket returns a ticket in the state. The boolean returns whether the ticket was found.

func (*State) ProcessEvent

func (s *State) ProcessEvent(event events.Event) error

ProcessEvent folds the supplied event in to the current aggregates.

type Ticket

type Ticket struct {
	ID       TicketID
	Status   TicketStatus
	IssuedAt time.Time
}

Ticket is an issued ticket for a car in a carpark

func (*Ticket) GetTariff

func (t *Ticket) GetTariff(now time.Time) (int, error)

GetTariff gets the current price of a ticket

func (*Ticket) IsValidTransition

func (t *Ticket) IsValidTransition(event events.Event) bool

IsValidTransition determines whether the event could be applied, disregarding ID

type TicketID

type TicketID string

TicketID is a type alias of a string

type TicketStatus

type TicketStatus int

TicketStatus is an enum for tracking state of a ticket. A stringer is generated for this type.

const (
	// TicketStatusIssued is the initial state of a new ticket
	TicketStatusIssued TicketStatus = iota
	// TicketStatusPaid means that the ticket has been paid for
	TicketStatusPaid
)

func (TicketStatus) String

func (i TicketStatus) String() string

Jump to

Keyboard shortcuts

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