diff --git a/src/Bundle/ChillMainBundle/Controller/GenderApiController.php b/src/Bundle/ChillMainBundle/Controller/GenderApiController.php new file mode 100644 index 000000000..567756ba7 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/GenderApiController.php @@ -0,0 +1,15 @@ +addOrderBy('e.order', 'ASC'); + } +} \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index b406f56f1..ca293cdd3 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Controller\CivilityApiController; use Chill\MainBundle\Controller\CivilityController; use Chill\MainBundle\Controller\CountryApiController; use Chill\MainBundle\Controller\CountryController; +use Chill\MainBundle\Controller\GenderApiController; use Chill\MainBundle\Controller\GenderController; use Chill\MainBundle\Controller\GeographicalUnitApiController; use Chill\MainBundle\Controller\LanguageController; @@ -813,6 +814,21 @@ class ChillMainExtension extends Extension implements ], ], ], + [ + 'class' => Gender::class, + 'name' => 'gender', + 'base_path' => '/api/1.0/main/gender', + 'base_role' => 'ROLE_USER', + 'controller' => GenderApiController::class, + 'actions' => [ + '_index' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true, + ], + ], + ], + ], [ 'class' => GeographicalUnitLayer::class, 'controller' => GeographicalUnitApiController::class, diff --git a/src/Bundle/ChillMainBundle/Entity/Gender.php b/src/Bundle/ChillMainBundle/Entity/Gender.php index bd8b26b68..2c4667e46 100644 --- a/src/Bundle/ChillMainBundle/Entity/Gender.php +++ b/src/Bundle/ChillMainBundle/Entity/Gender.php @@ -6,7 +6,7 @@ use Chill\MainBundle\Repository\GenderRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; - +#[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['chill_main_gender' => Gender::class])] #[ORM\Entity(repositoryClass: GenderRepository::class)] #[ORM\Table(name: 'chill_main_gender')] class Gender diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js index c9c77991f..3c58b67e9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/OnTheFly.js @@ -24,6 +24,12 @@ const getCivilities = () => throw Error('Error with request resource response'); }); +const getGenders = () => + fetch('/api/1.0/main/gender.json').then(response => { + if (response.ok) { return response.json(); } + throw Error('Error with request resource response'); + }); + const getCentersForPersonCreation = () => makeFetch('GET', '/api/1.0/person/creation/authorized-centers', null); /* @@ -67,6 +73,7 @@ export { getPerson, getPersonAltNames, getCivilities, + getGenders, postPerson, patchPerson }; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index d39a69d73..88c38cfbb 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Serializer\Normalizer; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Civility; +use Chill\MainBundle\Entity\Gender; use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension; @@ -112,7 +113,9 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar break; case 'gender': - $person->setGender($data[$item]); + $gender = $this->denormalizer->denormalize($data[$item], Gender::class, $format, []); + + $person->setGender($gender); break; @@ -199,7 +202,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar 'phonenumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $context), 'mobilenumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $context), 'email' => $person->getEmail(), - 'gender' => $person->getGender(), + 'gender' => $this->normalizer->normalize($person->getGender(), $format, $context), 'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context), ];