123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package model
- import (
- "errors"
- "time"
- )
- type HandlingActivity struct {
- Type HandlingEventType
- Location UNLocode
- VoyageNumber VoyageNumber
- }
- type HandlingEvent struct {
- TrackingID TrackingID
- Activity HandlingActivity
- }
- type HandlingEventType int
- const (
- NotHandled HandlingEventType = iota
- Load
- Unload
- Receive
- Claim
- Customs
- )
- func (t HandlingEventType) String() string {
- switch t {
- case NotHandled:
- return "Not Handled"
- case Load:
- return "Load"
- case Unload:
- return "Unload"
- case Receive:
- return "Receive"
- case Claim:
- return "Claim"
- case Customs:
- return "Customs"
- }
- return ""
- }
- type HandlingHistory struct {
- HandlingEvents []HandlingEvent
- }
- func (h HandlingHistory) MostRecentlyCompletedEvent() (HandlingEvent, error) {
- if len(h.HandlingEvents) == 0 {
- return HandlingEvent{}, errors.New("delivery history is empty")
- }
- return h.HandlingEvents[len(h.HandlingEvents)-1], nil
- }
- type HandlingEventRepository interface {
- Store(e HandlingEvent)
- QueryHandlingHistory(TrackingID) HandlingHistory
- }
- type HandlingEventFactory struct {
- CargoRepository CargoRepository
- VoyageRepository VoyageRepository
- LocationRepository LocationRepository
- }
- func (f *HandlingEventFactory) CreateHandlingEvent(registered time.Time, completed time.Time, id TrackingID,
- voyageNumber VoyageNumber, unLocode UNLocode, eventType HandlingEventType) (HandlingEvent, error) {
- if _, err := f.CargoRepository.Find(id); err != nil {
- return HandlingEvent{}, err
- }
- if _, err := f.VoyageRepository.Find(voyageNumber); err != nil {
-
- if len(voyageNumber) > 0 {
- return HandlingEvent{}, err
- }
- }
- if _, err := f.LocationRepository.Find(unLocode); err != nil {
- return HandlingEvent{}, err
- }
- return HandlingEvent{
- TrackingID: id,
- Activity: HandlingActivity{
- Type: eventType,
- Location: unLocode,
- VoyageNumber: voyageNumber,
- },
- }, nil
- }
|