Documentation
¶
Overview ¶
Package shipping contains the heart of the domain model.
Index ¶
- Variables
- type Cargo
- type CargoRepository
- type CarrierMovement
- type Delivery
- type HandlingActivity
- type HandlingEvent
- type HandlingEventFactory
- type HandlingEventRepository
- type HandlingEventType
- type HandlingHistory
- type Itinerary
- type Leg
- type Location
- type LocationRepository
- type RouteSpecification
- type RoutingService
- type RoutingStatus
- type Schedule
- type TrackingID
- type TransportStatus
- type UNLocode
- type Voyage
- type VoyageNumber
- type VoyageRepository
Constants ¶
This section is empty.
Variables ¶
var ( Stockholm = &Location{SESTO, "Stockholm"} Melbourne = &Location{AUMEL, "Melbourne"} Hongkong = &Location{CNHKG, "Hongkong"} NewYork = &Location{USNYC, "New York"} Chicago = &Location{USCHI, "Chicago"} Tokyo = &Location{JNTKO, "Tokyo"} Hamburg = &Location{DEHAM, "Hamburg"} Rotterdam = &Location{NLRTM, "Rotterdam"} Helsinki = &Location{FIHEL, "Helsinki"} )
Sample locations.
var ( V100 = NewVoyage("V100", Schedule{ []CarrierMovement{ {DepartureLocation: CNHKG, ArrivalLocation: JNTKO}, {DepartureLocation: JNTKO, ArrivalLocation: USNYC}, }, }) V300 = NewVoyage("V300", Schedule{ []CarrierMovement{ {DepartureLocation: JNTKO, ArrivalLocation: NLRTM}, {DepartureLocation: NLRTM, ArrivalLocation: DEHAM}, {DepartureLocation: DEHAM, ArrivalLocation: AUMEL}, {DepartureLocation: AUMEL, ArrivalLocation: JNTKO}, }, }) V400 = NewVoyage("V400", Schedule{ []CarrierMovement{ {DepartureLocation: DEHAM, ArrivalLocation: SESTO}, {DepartureLocation: SESTO, ArrivalLocation: FIHEL}, {DepartureLocation: FIHEL, ArrivalLocation: DEHAM}, }, }) )
A set of sample voyages.
var ( V0100S = NewVoyage("0100S", Schedule{[]CarrierMovement{}}) V0200T = NewVoyage("0200T", Schedule{[]CarrierMovement{}}) V0300A = NewVoyage("0300A", Schedule{[]CarrierMovement{}}) V0301S = NewVoyage("0301S", Schedule{[]CarrierMovement{}}) V0400S = NewVoyage("0400S", Schedule{[]CarrierMovement{}}) )
These voyages are hard-coded into the current pathfinder. Make sure they exist.
var ErrUnknownCargo = errors.New("unknown cargo")
ErrUnknownCargo is used when a cargo could not be found.
var ErrUnknownLocation = errors.New("unknown location")
ErrUnknownLocation is used when a location could not be found.
var ErrUnknownVoyage = errors.New("unknown voyage")
ErrUnknownVoyage is used when a voyage could not be found.
Functions ¶
This section is empty.
Types ¶
type Cargo ¶
type Cargo struct { TrackingID TrackingID Origin UNLocode RouteSpecification RouteSpecification Itinerary Itinerary Delivery Delivery }
Cargo is the central class in the domain model.
func NewCargo ¶
func NewCargo(id TrackingID, rs RouteSpecification) *Cargo
NewCargo creates a new, unrouted cargo.
func (*Cargo) AssignToRoute ¶
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 CargoRepository ¶
type CargoRepository interface { Store(cargo *Cargo) (bool, error) Find(id TrackingID) (*Cargo, error) FindAll() []*Cargo }
CargoRepository provides access a cargo store.
type CarrierMovement ¶
type CarrierMovement struct { DepartureLocation UNLocode ArrivalLocation UNLocode DepartureTime time.Time ArrivalTime time.Time }
CarrierMovement is a vessel voyage from one location to another.
type Delivery ¶
type Delivery struct { Itinerary Itinerary RouteSpecification RouteSpecification RoutingStatus RoutingStatus TransportStatus TransportStatus NextExpectedActivity HandlingActivity LastEvent HandlingEvent LastKnownLocation UNLocode CurrentVoyage VoyageNumber 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) 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 UNLocode VoyageNumber VoyageNumber }
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 CargoRepository VoyageRepository VoyageRepository LocationRepository LocationRepository }
HandlingEventFactory creates handling events.
func (*HandlingEventFactory) CreateHandlingEvent ¶
func (f *HandlingEventFactory) CreateHandlingEvent(registered time.Time, completed time.Time, id TrackingID, voyageNumber VoyageNumber, unLocode 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 ¶
FinalArrivalLocation returns the end of the itinerary.
func (Itinerary) FinalArrivalTime ¶
FinalArrivalTime returns the expected arrival time at final destination.
func (Itinerary) InitialDepartureLocation ¶
InitialDepartureLocation returns the start of the itinerary.
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 VoyageNumber `json:"voyage_number"` LoadLocation UNLocode `json:"from"` UnloadLocation 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
type Location ¶
Location is a location is our model is stops on a journey, such as cargo origin or destination, or carrier movement endpoints.
type LocationRepository ¶
type LocationRepository interface { Find(locode UNLocode) (*Location, error) FindAll() []*Location }
LocationRepository provides access a location store.
type RouteSpecification ¶
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 RoutingService ¶
type RoutingService interface { // FetchRoutesForSpecification finds all possible routes that satisfy a // given specification. FetchRoutesForSpecification(rs RouteSpecification) []Itinerary }
RoutingService is a domain service for routing cargos.
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 Schedule ¶
type Schedule struct {
CarrierMovements []CarrierMovement
}
Schedule describes a voyage schedule.
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
type UNLocode ¶
type UNLocode string
UNLocode is the United Nations location code that uniquely identifies a particular location.
http://www.unece.org/cefact/locode/ http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE
type Voyage ¶
type Voyage struct { VoyageNumber VoyageNumber Schedule Schedule }
Voyage is a uniquely identifiable series of carrier movements.
func NewVoyage ¶
func NewVoyage(n VoyageNumber, s Schedule) *Voyage
NewVoyage creates a voyage with a voyage number and a provided schedule.
type VoyageRepository ¶
type VoyageRepository interface {
Find(VoyageNumber) (*Voyage, error)
}
VoyageRepository provides access a voyage store.