From cea7160d5aae710d545b7b955f3e724cfbf7bbd5 Mon Sep 17 00:00:00 2001 From: LenaertsJ Date: Mon, 6 Dec 2021 13:04:19 +0000 Subject: [PATCH] Fix bug posting birth- and deathdate --- CHANGELOG.md | 1 + .../Normalizer/PersonJsonNormalizer.php | 11 +++----- .../ChillPersonBundle/chill.api.specs.yaml | 26 +++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b81ca9783..337be5fe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ and this project adheres to * add an endpoint for checking permissions. See https://gitlab.com/Chill-Projet/chill-bundles/-/merge_requests/232 * [activity] for a new activity: suggest and create on-the-fly locations based on the accompanying course location + location of the suggested parties * [calendar] for a new rdv: suggest and create on-the-fly locations based on the accompanying course location + location of the suggested parties +* [bugfix] posting of birth- and deathdate through api fixed. ### Test release 2021-11-22 diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index c0ba0201a..7049b7c00 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Repository\PersonRepository; use DateTime; +use DateTimeImmutable; use LogicException; use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; @@ -114,18 +115,14 @@ class PersonJsonNormalizer implements case 'birthdate': $object = $this->denormalizer->denormalize($data[$item], DateTime::class, $format, $context); - if ($object instanceof DateTime) { - $person->setBirthdate($object); - } + $person->setBirthdate($object); break; case 'deathdate': - $object = $this->denormalizer->denormalize($data[$item], DateTime::class, $format, $context); + $object = $this->denormalizer->denormalize($data[$item], DateTimeImmutable::class, $format, $context); - if ($object instanceof DateTime) { - $person->setDeathdate($object); - } + $person->setDeathdate($object); break; diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index c67884a19..3c49cc264 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -353,6 +353,19 @@ paths: application/json: schema: $ref: "#/components/schemas/Person" + examples: + Update a person: + value: + type: "person" + firstName: "string" + lastName: "string" + birthdate: + datetime: "2016-06-01T00:00:00+02:00" + deathdate: + datetime: "2021-06-01T00:00:00+02:00" + phonenumber: "string" + mobilenumber: "string" + gender: "male" responses: 401: description: "Unauthorized" @@ -375,6 +388,19 @@ paths: application/json: schema: $ref: "#/components/schemas/Person" + examples: + Create a new person: + value: + type: "person" + firstName: "string" + lastName: "string" + birthdate: + datetime: "2016-06-01T00:00:00+02:00" + deathdate: + datetime: "2021-06-01T00:00:00+02:00" + phonenumber: "string" + mobilenumber: "string" + gender: "male" responses: 200: description: "OK"