flight

package
v0.0.0-...-da8027b Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AssignNewCommand    = stream.CommandType("AssignNew")
	StartRouteCommand   = stream.CommandType("StartRoute")
	StopRouteCommand    = stream.CommandType("StopRoute")
	StartCheckInCommand = stream.CommandType("StartCheckIn")
)
View Source
const (
	// Flight context
	AssignedEvent       = stream.EventType("FlightCreated")
	RouteStartedEvent   = stream.EventType("FlightRouteStarted")
	RouteStoppedEvent   = stream.EventType("FlightRouteStopped")
	CheckInStartedEvent = stream.EventType("FlightCheckInStarted")
)
View Source
const Stream = stream.Type("Flight")

Variables

View Source
var (
	ErrTransition    = errors.New("state transition")
	ErrAlreadyExists = errors.New("already exists")
	ErrUnknownID     = errors.New("unknown id")
)

Functions

func AssignNew

func AssignNew(sid stream.ID, blank *Flight, c Assign) error

func MutatorController

func MutatorController(
	ctx context.Context,
	eventBus eventbus.Bus,
	commandBus commandbus.Bus,
	activeFlightsProjection *ActiveFlightsProjection,
) (err error)

func NewAssignCommand

func NewAssignCommand(sid stream.ID, c Assign) stream.Command

func NewStartCheckInCommand

func NewStartCheckInCommand(sid stream.ID, c StartCheckIn) stream.Command

func NewStartRouteCommand

func NewStartRouteCommand(sid stream.ID, c StartRoute) stream.Command

func NewStopRouteCommand

func NewStopRouteCommand(sid stream.ID, c StopRoute) stream.Command

func ProjectionController

func ProjectionController(
	ctx context.Context,
	eventBus eventbus.Bus,
	proj ...Projection,
) error

Types

type ActiveFlightsProjection

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

func NewActiveFlightsProjection

func NewActiveFlightsProjection() *ActiveFlightsProjection

func (*ActiveFlightsProjection) FlightAssignedNew

func (p *ActiveFlightsProjection) FlightAssignedNew(_ context.Context, sid stream.ID, v stream.Version, e Assigned) error

func (*ActiveFlightsProjection) FlightCheckInStarted

func (p *ActiveFlightsProjection) FlightCheckInStarted(_ context.Context, sid stream.ID, v stream.Version, e CheckInStarted) error

func (*ActiveFlightsProjection) FlightExists

func (p *ActiveFlightsProjection) FlightExists(aircraftID stream.ID) bool

func (*ActiveFlightsProjection) FlightID

func (p *ActiveFlightsProjection) FlightID(aircraftID stream.ID) stream.ID

func (*ActiveFlightsProjection) FlightRouteStarted

func (p *ActiveFlightsProjection) FlightRouteStarted(_ context.Context, sid stream.ID, v stream.Version, e RouteStarted) error

func (*ActiveFlightsProjection) FlightRouteStopped

func (p *ActiveFlightsProjection) FlightRouteStopped(_ context.Context, sid stream.ID, v stream.Version, e RouteStopped) error

type Airport

type Airport struct {
	Code string
	Name string
}

func (Airport) String

func (a Airport) String() string

func (Airport) Validate

func (a Airport) Validate() error

type Assign

type Assign struct {
	NewFlightID stream.ID
	AircraftID  stream.ID
	AirlineID   stream.ID
	ManagerID   stream.ID
	From        Airport
	To          Airport
}

func (Assign) Validate

func (c Assign) Validate() (err error)

Validate checks if values are correct.

type Assigned

type Assigned struct {
	FlightID     stream.ID
	AircraftID   stream.ID
	AirlineID    stream.ID
	ManagerID    stream.ID
	From         Airport
	To           Airport
	OperationLog []OperationLog
	State        State
	CreatedAt    time.Time
}

type CheckInStarted

type CheckInStarted struct {
	AircraftID   stream.ID
	AirlineID    stream.ID
	ManagerID    stream.ID
	OperationLog []OperationLog
	From         Airport
	To           Airport
	State        State
	Time         time.Time
}

type Codec

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

func NewCodec

func NewCodec() *Codec

func (*Codec) Commands

func (c *Codec) Commands() *escodec.DefaultCodec

func (*Codec) Events

func (c *Codec) Events() *escodec.DefaultCodec

func (*Codec) Replies

func (c *Codec) Replies() *escodec.DefaultCodec

type Flight

type Flight struct {
	stream.Stream
	// contains filtered or unexported fields
}

func (*Flight) Apply

func (a *Flight) Apply(e stream.Event, isNew bool)

func (*Flight) StartCheckIn

func (a *Flight) StartCheckIn(c StartCheckIn) error

func (*Flight) StartRoute

func (a *Flight) StartRoute(c StartRoute) error

func (*Flight) StopRoute

func (a *Flight) StopRoute(c StopRoute) error

func (*Flight) Type

func (a *Flight) Type() stream.Type

type FlightsProjection

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

func NewFlightsProjection

func NewFlightsProjection() *FlightsProjection

func (*FlightsProjection) Find

func (p *FlightsProjection) Find(sid stream.ID) (Model, error)

func (*FlightsProjection) FlightAssignedNew

func (p *FlightsProjection) FlightAssignedNew(_ context.Context, sid stream.ID, v stream.Version, e Assigned) error

func (*FlightsProjection) FlightCheckInStarted

func (p *FlightsProjection) FlightCheckInStarted(_ context.Context, sid stream.ID, v stream.Version, e CheckInStarted) error

func (*FlightsProjection) FlightRouteStarted

func (p *FlightsProjection) FlightRouteStarted(_ context.Context, sid stream.ID, v stream.Version, e RouteStarted) error

func (*FlightsProjection) FlightRouteStopped

func (p *FlightsProjection) FlightRouteStopped(_ context.Context, sid stream.ID, v stream.Version, e RouteStopped) error

func (*FlightsProjection) Flights

func (p *FlightsProjection) Flights() map[stream.ID]Model

type Model

type Model struct {
	FlightID   string
	AircraftID string
	AirlineID  string
	ManagerID  string
	State      string
	TakeOff    time.Time
	Landing    time.Time
	CreatedAt  time.Time
	From       string
	To         string
}

type Mutator

type Mutator interface {
	AssignNew(context.Context, *Flight, Assign) error
	StartRouteFlight(context.Context, *Flight, StartRoute) error
	StopRouteFlight(context.Context, *Flight, StopRoute) error
	StartCheckIn(context.Context, *Flight, StartCheckIn) error
}

func NewMutator

func NewMutator(
	activeFlightProj *ActiveFlightsProjection,
) Mutator

type OperationLog

type OperationLog struct {
	Operation string
	ManagerID stream.ID
	Time      time.Time
	From      State
	To        State
}

type Processor

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

func NewProcessor

func NewProcessor(proj ...Projection) *Processor

func (*Processor) Handle

func (p *Processor) Handle(ctx context.Context, e stream.Event) (err error)

type Projection

type Projection interface {
	FlightAssignedNew(context.Context, stream.ID, stream.Version, Assigned) error
	FlightRouteStarted(context.Context, stream.ID, stream.Version, RouteStarted) error
	FlightRouteStopped(context.Context, stream.ID, stream.Version, RouteStopped) error
	FlightCheckInStarted(context.Context, stream.ID, stream.Version, CheckInStarted) error
}

type RouteStarted

type RouteStarted struct {
	AircraftID   stream.ID
	AirlineID    stream.ID
	ManagerID    stream.ID
	OperationLog []OperationLog
	From         Airport
	To           Airport
	State        State
	Time         time.Time
	Autostart    bool
}

type RouteStopped

type RouteStopped struct {
	AircraftID   stream.ID
	AirlineID    stream.ID
	ManagerID    stream.ID
	OperationLog []OperationLog
	From         Airport
	To           Airport
	State        State
	Time         time.Time
	Autostop     bool
}

type StartCheckIn

type StartCheckIn struct {
	ManagerID stream.ID
	Time      time.Time
}

type StartRoute

type StartRoute struct {
	Autostart bool
	ManagerID stream.ID
	Time      time.Time
}

type State

type State int
const (
	Pending State = 0
	CheckIn State = 15
	EnRoute State = 20
	Arrival State = 25
)

func (State) String

func (s State) String() (n string)

type StopRoute

type StopRoute struct {
	Autostop  bool
	Time      time.Time
	ManagerID stream.ID
}

Jump to

Keyboard shortcuts

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