|
|
|
@@ -35,24 +35,24 @@ class TripApiToEntityMapper implements MapperInterface |
|
|
|
} |
|
|
|
|
|
|
|
// For new trips, we need the vessel and locations |
|
|
|
if (!$dto->vessel?->id) { |
|
|
|
if (!$dto->vesselIri->id) { |
|
|
|
throw new \Exception('Vessel is required for new trips'); |
|
|
|
} |
|
|
|
if (!$dto->startLocation?->id || !$dto->endLocation?->id) { |
|
|
|
if (!$dto->startLocationIri->id || !$dto->endLocationIri->id) { |
|
|
|
throw new \Exception('Start and end locations are required for new trips'); |
|
|
|
} |
|
|
|
|
|
|
|
$vessel = $this->vesselRepository->find($dto->vessel->id); |
|
|
|
$vessel = $this->vesselRepository->find($dto->vesselIri->id); |
|
|
|
if (!$vessel) { |
|
|
|
throw new \Exception('Vessel not found'); |
|
|
|
} |
|
|
|
|
|
|
|
$startLocation = $this->locationRepository->find($dto->startLocation->id); |
|
|
|
$startLocation = $this->locationRepository->find($dto->startLocationIri->id); |
|
|
|
if (!$startLocation) { |
|
|
|
throw new \Exception('Start location not found'); |
|
|
|
} |
|
|
|
|
|
|
|
$endLocation = $this->locationRepository->find($dto->endLocation->id); |
|
|
|
$endLocation = $this->locationRepository->find($dto->endLocationIri->id); |
|
|
|
if (!$endLocation) { |
|
|
|
throw new \Exception('End location not found'); |
|
|
|
} |
|
|
|
@@ -79,6 +79,31 @@ class TripApiToEntityMapper implements MapperInterface |
|
|
|
$entity->setEndDate($dto->endDate); |
|
|
|
$entity->setNote($dto->note); |
|
|
|
|
|
|
|
if ($dto->vesselIri->id) { |
|
|
|
$vessel = $this->vesselRepository->find($dto->vesselIri->id); |
|
|
|
if (!$vessel) { |
|
|
|
throw new \Exception('Vessel not found'); |
|
|
|
} |
|
|
|
$entity->setVessel($vessel); |
|
|
|
} |
|
|
|
|
|
|
|
if ($dto->startLocationIri->id) { |
|
|
|
$startLocation = $this->locationRepository->find($dto->startLocationIri->id); |
|
|
|
if (!$startLocation) { |
|
|
|
throw new \Exception('Start location not found'); |
|
|
|
} |
|
|
|
$entity->setStartLocation($startLocation); |
|
|
|
} |
|
|
|
|
|
|
|
if ($dto->endLocationIri->id) { |
|
|
|
$endLocation = $this->locationRepository->find($dto->endLocationIri->id); |
|
|
|
if (!$endLocation) { |
|
|
|
throw new \Exception('End location not found'); |
|
|
|
} |
|
|
|
$entity->setEndLocation($endLocation); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $entity; |
|
|
|
} |
|
|
|
} |