|
|
|
@@ -17,10 +17,10 @@ use Symfonycasts\MicroMapper\MicroMapperInterface; |
|
|
|
class UserApiToEntityMapper implements MapperInterface |
|
|
|
{ |
|
|
|
public function __construct( |
|
|
|
private UserRepository $userRepository, |
|
|
|
private UserRepository $repository, |
|
|
|
private UserPasswordHasherInterface $userPasswordHasher, |
|
|
|
private MicroMapperInterface $microMapper, |
|
|
|
private PropertyAccessorInterface $propertyAccessor, |
|
|
|
private MicroMapperInterface $microMapper, |
|
|
|
private PropertyAccessorInterface $propertyAccessor, |
|
|
|
) |
|
|
|
{ |
|
|
|
} |
|
|
|
@@ -30,12 +30,12 @@ class UserApiToEntityMapper implements MapperInterface |
|
|
|
$dto = $from; |
|
|
|
assert($dto instanceof UserApi); |
|
|
|
|
|
|
|
$userEntity = $dto->id ? $this->userRepository->find($dto->id) : new User(); |
|
|
|
if (!$userEntity) { |
|
|
|
$entity = $dto->id ? $this->repository->find($dto->id) : new User(); |
|
|
|
if (!$entity) { |
|
|
|
throw new \Exception('User not found'); |
|
|
|
} |
|
|
|
|
|
|
|
return $userEntity; |
|
|
|
return $entity; |
|
|
|
} |
|
|
|
|
|
|
|
public function populate(object $from, object $to, array $context): object |
|
|
|
@@ -53,11 +53,6 @@ class UserApiToEntityMapper implements MapperInterface |
|
|
|
} |
|
|
|
|
|
|
|
$userPostsEntities = new ArrayCollection(); |
|
|
|
foreach ($dto->posts as $userPostApi) { |
|
|
|
$userPostsEntities[] = $this->microMapper->map($userPostApi, Posting::class, [ |
|
|
|
MicroMapperInterface::MAX_DEPTH => 1, |
|
|
|
]); |
|
|
|
} |
|
|
|
$this->propertyAccessor->setValue($entity, 'postings', $userPostsEntities); |
|
|
|
|
|
|
|
return $entity; |
|
|
|
|