From 91ba08dfa14d774695c306c7b918d42de38387aa Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 4 Feb 2022 10:34:32 +0100 Subject: [PATCH] accompanying course: normalize the requestor entity --- .../AccompanyingCourseApiController.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index c66488869..10f733307 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -234,17 +234,20 @@ final class AccompanyingCourseApiController extends ApiController $requestor = null; $exceptions = []; - foreach ([Person::class, ThirdParty::class] as $class) { - try { - $requestor = $this->getSerializer() - ->deserialize($request->getContent(), $class, $_format, []); - } catch (RuntimeException $e) { - $exceptions[] = $e; + try { + $contentAsArray = json_decode($request->getContent(), true); + $entityType = $contentAsArray['type']; + if ($entityType === 'person') { + $requestor = $this->getSerializer()->deserialize($request->getContent(), Person::class, $_format, []); + } elseif ($entityType === 'thirdparty') { + $requestor = $this->getSerializer()->deserialize($request->getContent(), ThirdParty::class, $_format, []); } + } catch (RuntimeException $e) { + $exceptions[] = $e; } 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);