From 24b1d19493e4f0975b8888b34664222584e722eb Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 7 Apr 2025 09:26:55 +0200 Subject: [PATCH] fix vessel creation --- httpdocs/src/Mapper/UserTripApiToEntityMapper.php | 10 ++++------ httpdocs/src/Mapper/VesselApiToEntityMapper.php | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/httpdocs/src/Mapper/UserTripApiToEntityMapper.php b/httpdocs/src/Mapper/UserTripApiToEntityMapper.php index 5186366..857c870 100644 --- a/httpdocs/src/Mapper/UserTripApiToEntityMapper.php +++ b/httpdocs/src/Mapper/UserTripApiToEntityMapper.php @@ -19,6 +19,8 @@ class UserTripApiToEntityMapper implements MapperInterface { public function __construct( private UserTripRepository $repository, + private TripRepository $tripRepository, + private UserRepository $userRepository, private MediaObjectRepository $mediaObjectRepository, private MicroMapperInterface $microMapper ) { @@ -42,16 +44,12 @@ class UserTripApiToEntityMapper implements MapperInterface throw new \Exception('Trip and User are required for new user trips'); } - $trip = $this->microMapper->map($dto->tripIri, Trip::class, [ - MicroMapperInterface::MAX_DEPTH => 1, - ]); + $trip = $this->tripRepository->find($dto->tripIri->id); if (!$trip) { throw new \Exception('Trip not found'); } - $user = $this->microMapper->map($dto->userIri, User::class, [ - MicroMapperInterface::MAX_DEPTH => 1, - ]); + $user = $this->userRepository->find($dto->userIri->id); if (!$user) { throw new \Exception('User not found'); } diff --git a/httpdocs/src/Mapper/VesselApiToEntityMapper.php b/httpdocs/src/Mapper/VesselApiToEntityMapper.php index 431b097..1946249 100644 --- a/httpdocs/src/Mapper/VesselApiToEntityMapper.php +++ b/httpdocs/src/Mapper/VesselApiToEntityMapper.php @@ -33,11 +33,11 @@ class VesselApiToEntityMapper implements MapperInterface } // For new vessels, we need the shipping company - if (!$dto->company?->id) { + if (!$dto->companyIri) { throw new \Exception('ShippingCompany is required for new vessels'); } - $company = $this->shippingCompanyRepository->find($dto->company->id); + $company = $this->shippingCompanyRepository->find($dto->companyIri->id); if (!$company) { throw new \Exception('ShippingCompany not found'); }