1 // Package inspection provides means to inspect cargos.
5 "github.com/go-kit/kit/examples/shipping/cargo"
8 // EventHandler provides means of subscribing to inspection events.
9 type EventHandler interface {
10 CargoWasMisdirected(*cargo.Cargo)
11 CargoHasArrived(*cargo.Cargo)
14 // Service provides cargo inspection operations.
15 type Service interface {
16 // InspectCargo inspects cargo and send relevant notifications to
17 // interested parties, for example if a cargo has been misdirected, or
18 // unloaded at the final destination.
19 InspectCargo(id cargo.TrackingID)
23 cargos cargo.Repository
24 events cargo.HandlingEventRepository
28 // TODO: Should be transactional
29 func (s *service) InspectCargo(id cargo.TrackingID) {
30 c, err := s.cargos.Find(id)
35 h := s.events.QueryHandlingHistory(id)
37 c.DeriveDeliveryProgress(h)
39 if c.Delivery.IsMisdirected {
40 s.handler.CargoWasMisdirected(c)
43 if c.Delivery.IsUnloadedAtDestination {
44 s.handler.CargoHasArrived(c)
50 // NewService creates a inspection service with necessary dependencies.
51 func NewService(cargos cargo.Repository, events cargo.HandlingEventRepository, handler EventHandler) Service {
52 return &service{cargos, events, handler}