package cargo
import "github.com/go-kit/kit/examples/shipping/cargo"
Package cargo contains the heart of the domain model.
Index ¶
- Variables
- type Cargo
- func New(id TrackingID, rs RouteSpecification) *Cargo
- func (c *Cargo) AssignToRoute(itinerary Itinerary)
- func (c *Cargo) DeriveDeliveryProgress(history HandlingHistory)
- func (c *Cargo) SpecifyNewRoute(rs RouteSpecification)
- type Delivery
- func DeriveDeliveryFrom(rs RouteSpecification, itinerary Itinerary, history HandlingHistory) Delivery
- func (d Delivery) IsOnTrack() bool
- func (d Delivery) UpdateOnRouting(rs RouteSpecification, itinerary Itinerary) Delivery
- type HandlingActivity
- type HandlingEvent
- type HandlingEventFactory
- type HandlingEventRepository
- type HandlingEventType
- type HandlingHistory
- type Itinerary
- func (i Itinerary) FinalArrivalLocation() location.UNLocode
- func (i Itinerary) FinalArrivalTime() time.Time
- func (i Itinerary) InitialDepartureLocation() location.UNLocode
- func (i Itinerary) IsEmpty() bool
- func (i Itinerary) IsExpected(event HandlingEvent) bool
- type Leg
- type Repository
- type RouteSpecification
- type RoutingStatus
- type TrackingID
- type TransportStatus
Variables ¶
ErrUnknown is used when a cargo could not be found.
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 ¶
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 ¶
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 ¶
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) IsEmpty ¶
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
Source Files ¶
cargo.go delivery.go handling.go itinerary.go
- Version
- v0.7.0
- Published
- Mar 19, 2018
- Platform
- js/wasm
- Imports
- 6 packages
- Last checked
- 4 days ago –
Tools for package owners.