6 "github.com/go-kit/kit/examples/shipping/location"
7 "github.com/go-kit/kit/examples/shipping/voyage"
10 // Leg describes the transportation between two locations on a voyage.
12 VoyageNumber voyage.Number `json:"voyage_number"`
13 LoadLocation location.UNLocode `json:"from"`
14 UnloadLocation location.UNLocode `json:"to"`
15 LoadTime time.Time `json:"load_time"`
16 UnloadTime time.Time `json:"unload_time"`
19 // NewLeg creates a new itinerary leg.
20 func NewLeg(voyageNumber voyage.Number, loadLocation, unloadLocation location.UNLocode, loadTime, unloadTime time.Time) Leg {
22 VoyageNumber: voyageNumber,
23 LoadLocation: loadLocation,
24 UnloadLocation: unloadLocation,
26 UnloadTime: unloadTime,
30 // Itinerary specifies steps required to transport a cargo from its origin to
32 type Itinerary struct {
33 Legs []Leg `json:"legs"`
36 // InitialDepartureLocation returns the start of the itinerary.
37 func (i Itinerary) InitialDepartureLocation() location.UNLocode {
39 return location.UNLocode("")
41 return i.Legs[0].LoadLocation
44 // FinalArrivalLocation returns the end of the itinerary.
45 func (i Itinerary) FinalArrivalLocation() location.UNLocode {
47 return location.UNLocode("")
49 return i.Legs[len(i.Legs)-1].UnloadLocation
52 // FinalArrivalTime returns the expected arrival time at final destination.
53 func (i Itinerary) FinalArrivalTime() time.Time {
54 return i.Legs[len(i.Legs)-1].UnloadTime
57 // IsEmpty checks if the itinerary contains at least one leg.
58 func (i Itinerary) IsEmpty() bool {
59 return i.Legs == nil || len(i.Legs) == 0
62 // IsExpected checks if the given handling event is expected when executing
64 func (i Itinerary) IsExpected(event HandlingEvent) bool {
69 switch event.Activity.Type {
71 return i.InitialDepartureLocation() == event.Activity.Location
73 for _, l := range i.Legs {
74 if l.LoadLocation == event.Activity.Location && l.VoyageNumber == event.Activity.VoyageNumber {
80 for _, l := range i.Legs {
81 if l.UnloadLocation == event.Activity.Location && l.VoyageNumber == event.Activity.VoyageNumber {
87 return i.FinalArrivalLocation() == event.Activity.Location