/**
  * @param RouteCandidateDto $aRouteCandidate
  * @return Itinerary
  */
 public function toItinerary(RouteCandidateDto $aRouteCandidate)
 {
     $legs = array();
     foreach ($aRouteCandidate->getLegs() as $legDto) {
         $legs[] = new Leg($legDto->getLoadLocation(), $legDto->getUnloadLocation(), new \DateTime($legDto->getLoadTime()), new \DateTime($legDto->getUnloadTime()));
     }
     return new Itinerary($legs);
 }
 /**
  * @param ResourceEvent $e
  * @return \CargoBackend\API\Booking\Dto\CargoRoutingDto
  * @throws \PhlyRestfully\Exception\UpdateException
  */
 public function onUpdate(ResourceEvent $e)
 {
     $trackingId = $e->getRouteMatch()->getParam('tracking_id');
     $data = $e->getParam('data');
     if (!isset($data->legs)) {
         throw new UpdateException("Legs missing in CargoRouting payload", 400);
     }
     $routeCandidate = new RouteCandidateDto();
     $routeCandidate->setLegs($this->toLegDtosFromData($data->legs));
     $this->bookingService->assignCargoToRoute($trackingId, $routeCandidate);
     return $this->bookingService->loadCargoForRouting($trackingId);
 }