cargo

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cargo contains the heart of the domain model.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknown = errors.New("unknown cargo")

ErrUnknown is used when a cargo could not be found.

Functions

This section is empty.

Types

type Cargo

type Cargo struct {
	TrackingID         TrackingID
	Origin             location.UNLocode
	RouteSpecification RouteSpecification
	Itinerary          Itinerary
	Delivery           Delivery
}

Cargo is the central class in the domain model.

func New

func New(id TrackingID, rs RouteSpecification) *Cargo

New creates a new, unrouted cargo.

func (*Cargo) AssignToRoute

func (c *Cargo) AssignToRoute(itinerary Itinerary)

AssignToRoute attaches a new itinerary to this cargo.

func (*Cargo) DeriveDeliveryProgress

func (c *Cargo) DeriveDeliveryProgress(history HandlingHistory)

DeriveDeliveryProgress updates all aspects of the cargo aggregate status based on the current route specification, itinerary and handling of the cargo.

func (*Cargo) SpecifyNewRoute

func (c *Cargo) SpecifyNewRoute(rs RouteSpecification)

SpecifyNewRoute specifies a new route for this cargo.

type Delivery

type Delivery struct {
	Itinerary               Itinerary
	RouteSpecification      RouteSpecification
	RoutingStatus           RoutingStatus
	TransportStatus         TransportStatus
	NextExpectedActivity    HandlingActivity
	LastEvent               HandlingEvent
	LastKnownLocation       location.UNLocode
	CurrentVoyage           voyage.Number
	ETA                     time.Time
	IsMisdirected           bool
	IsUnloadedAtDestination bool
}

Delivery is the actual transportation of the cargo, as opposed to the customer requirement (RouteSpecification) and the plan (Itinerary).

func DeriveDeliveryFrom

func DeriveDeliveryFrom(rs RouteSpecification, itinerary Itinerary, history HandlingHistory) Delivery

DeriveDeliveryFrom creates a new delivery snapshot based on the complete handling history of a cargo, as well as its route specification and itinerary.

func (Delivery) IsOnTrack

func (d Delivery) IsOnTrack() bool

IsOnTrack checks if the delivery is on track.

func (Delivery) UpdateOnRouting

func (d Delivery) UpdateOnRouting(rs RouteSpecification, itinerary Itinerary) Delivery

UpdateOnRouting creates a new delivery snapshot to reflect changes in routing, i.e. when the route specification or the itinerary has changed but no additional handling of the cargo has been performed.

type HandlingActivity

type HandlingActivity struct {
	Type         HandlingEventType
	Location     location.UNLocode
	VoyageNumber voyage.Number
}

HandlingActivity represents how and where a cargo can be handled, and can be used to express predictions about what is expected to happen to a cargo in the future.

type HandlingEvent

type HandlingEvent struct {
	TrackingID TrackingID
	Activity   HandlingActivity
}

HandlingEvent is used to register the event when, for instance, a cargo is unloaded from a carrier at a some location at a given time.

type HandlingEventFactory

type HandlingEventFactory struct {
	CargoRepository    Repository
	VoyageRepository   voyage.Repository
	LocationRepository location.Repository
}

HandlingEventFactory creates handling events.

func (*HandlingEventFactory) CreateHandlingEvent

func (f *HandlingEventFactory) CreateHandlingEvent(registered time.Time, completed time.Time, id TrackingID,
	voyageNumber voyage.Number, unLocode location.UNLocode, eventType HandlingEventType) (HandlingEvent, error)

CreateHandlingEvent creates a validated handling event.

type HandlingEventRepository

type HandlingEventRepository interface {
	Store(e HandlingEvent)
	QueryHandlingHistory(TrackingID) HandlingHistory
}

HandlingEventRepository provides access a handling event store.

type HandlingEventType

type HandlingEventType int

HandlingEventType describes type of a handling event.

const (
	NotHandled HandlingEventType = iota
	Load
	Unload
	Receive
	Claim
	Customs
)

Valid handling event types.

func (HandlingEventType) String

func (t HandlingEventType) String() string

type HandlingHistory

type HandlingHistory struct {
	HandlingEvents []HandlingEvent
}

HandlingHistory is the handling history of a cargo.

func (HandlingHistory) MostRecentlyCompletedEvent

func (h HandlingHistory) MostRecentlyCompletedEvent() (HandlingEvent, error)

MostRecentlyCompletedEvent returns most recently completed handling event.

type Itinerary

type Itinerary struct {
	Legs []Leg `json:"legs"`
}

Itinerary specifies steps required to transport a cargo from its origin to destination.

func (Itinerary) FinalArrivalLocation

func (i Itinerary) FinalArrivalLocation() location.UNLocode

FinalArrivalLocation returns the end of the itinerary.

func (Itinerary) FinalArrivalTime

func (i Itinerary) FinalArrivalTime() time.Time

FinalArrivalTime returns the expected arrival time at final destination.

func (Itinerary) InitialDepartureLocation

func (i Itinerary) InitialDepartureLocation() location.UNLocode

InitialDepartureLocation returns the start of the itinerary.

func (Itinerary) IsEmpty

func (i Itinerary) IsEmpty() bool

IsEmpty checks if the itinerary contains at least one leg.

func (Itinerary) IsExpected

func (i Itinerary) IsExpected(event HandlingEvent) bool

IsExpected checks if the given handling event is expected when executing this itinerary.

type Leg

type Leg struct {
	VoyageNumber   voyage.Number     `json:"voyage_number"`
	LoadLocation   location.UNLocode `json:"from"`
	UnloadLocation location.UNLocode `json:"to"`
	LoadTime       time.Time         `json:"load_time"`
	UnloadTime     time.Time         `json:"unload_time"`
}

Leg describes the transportation between two locations on a voyage.

func NewLeg

func NewLeg(voyageNumber voyage.Number, loadLocation, unloadLocation location.UNLocode, loadTime, unloadTime time.Time) Leg

NewLeg creates a new itinerary leg.

type Repository

type Repository interface {
	Store(cargo *Cargo) error
	Find(id TrackingID) (*Cargo, error)
	FindAll() []*Cargo
}

Repository provides access a cargo store.

type RouteSpecification

type RouteSpecification struct {
	Origin          location.UNLocode
	Destination     location.UNLocode
	ArrivalDeadline time.Time
}

RouteSpecification Contains information about a route: its origin, destination and arrival deadline.

func (RouteSpecification) IsSatisfiedBy

func (s RouteSpecification) IsSatisfiedBy(itinerary Itinerary) bool

IsSatisfiedBy checks whether provided itinerary satisfies this specification.

type RoutingStatus

type RoutingStatus int

RoutingStatus describes status of cargo routing.

const (
	NotRouted RoutingStatus = iota
	Misrouted
	Routed
)

Valid routing statuses.

func (RoutingStatus) String

func (s RoutingStatus) String() string

type TrackingID

type TrackingID string

TrackingID uniquely identifies a particular cargo.

func NextTrackingID

func NextTrackingID() TrackingID

NextTrackingID generates a new tracking ID. TODO: Move to infrastructure(?)

type TransportStatus

type TransportStatus int

TransportStatus describes status of cargo transportation.

const (
	NotReceived TransportStatus = iota
	InPort
	OnboardCarrier
	Claimed
	Unknown
)

Valid transport statuses.

func (TransportStatus) String

func (s TransportStatus) String() string

Jump to

Keyboard shortcuts

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