accompanying course: normalize the requestor entity

This commit is contained in:
nobohan 2022-02-04 10:34:32 +01:00
parent 2343a4a334
commit 91ba08dfa1

View File

@ -234,17 +234,20 @@ final class AccompanyingCourseApiController extends ApiController
$requestor = null; $requestor = null;
$exceptions = []; $exceptions = [];
foreach ([Person::class, ThirdParty::class] as $class) { try {
try { $contentAsArray = json_decode($request->getContent(), true);
$requestor = $this->getSerializer() $entityType = $contentAsArray['type'];
->deserialize($request->getContent(), $class, $_format, []); if ($entityType === 'person') {
} catch (RuntimeException $e) { $requestor = $this->getSerializer()->deserialize($request->getContent(), Person::class, $_format, []);
$exceptions[] = $e; } elseif ($entityType === 'thirdparty') {
$requestor = $this->getSerializer()->deserialize($request->getContent(), ThirdParty::class, $_format, []);
} }
} catch (RuntimeException $e) {
$exceptions[] = $e;
} }
if (null === $requestor) { if (null === $requestor) {
throw new BadRequestException('Could not find any person or requestor', 0, $exceptions[0]); throw new BadRequestException('Could not find any person or thirdparty', 0, null);
} }
$accompanyingPeriod->setRequestor($requestor); $accompanyingPeriod->setRequestor($requestor);