Create gender API and adjust serialization of gender property

This commit is contained in:
Julie Lenaerts 2024-10-01 11:41:19 +02:00
parent 236e8117d4
commit 406eba80d2
5 changed files with 44 additions and 3 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\MainBundle\Pagination\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
class GenderApiController extends ApiController
{
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator, $_format)
{
return $query->addOrderBy('e.order', 'ASC');
}
}

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Controller\CivilityApiController;
use Chill\MainBundle\Controller\CivilityController; use Chill\MainBundle\Controller\CivilityController;
use Chill\MainBundle\Controller\CountryApiController; use Chill\MainBundle\Controller\CountryApiController;
use Chill\MainBundle\Controller\CountryController; use Chill\MainBundle\Controller\CountryController;
use Chill\MainBundle\Controller\GenderApiController;
use Chill\MainBundle\Controller\GenderController; use Chill\MainBundle\Controller\GenderController;
use Chill\MainBundle\Controller\GeographicalUnitApiController; use Chill\MainBundle\Controller\GeographicalUnitApiController;
use Chill\MainBundle\Controller\LanguageController; 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, 'class' => GeographicalUnitLayer::class,
'controller' => GeographicalUnitApiController::class, 'controller' => GeographicalUnitApiController::class,

View File

@ -6,7 +6,7 @@ use Chill\MainBundle\Repository\GenderRepository;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation as Serializer;
#[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['chill_main_gender' => Gender::class])]
#[ORM\Entity(repositoryClass: GenderRepository::class)] #[ORM\Entity(repositoryClass: GenderRepository::class)]
#[ORM\Table(name: 'chill_main_gender')] #[ORM\Table(name: 'chill_main_gender')]
class Gender class Gender

View File

@ -24,6 +24,12 @@ const getCivilities = () =>
throw Error('Error with request resource response'); 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); const getCentersForPersonCreation = () => makeFetch('GET', '/api/1.0/person/creation/authorized-centers', null);
/* /*
@ -67,6 +73,7 @@ export {
getPerson, getPerson,
getPersonAltNames, getPersonAltNames,
getCivilities, getCivilities,
getGenders,
postPerson, postPerson,
patchPerson patchPerson
}; };

View File

@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface; use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension; use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
@ -112,7 +113,9 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
break; break;
case 'gender': case 'gender':
$person->setGender($data[$item]); $gender = $this->denormalizer->denormalize($data[$item], Gender::class, $format, []);
$person->setGender($gender);
break; break;
@ -199,7 +202,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
'phonenumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $context), 'phonenumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $context),
'mobilenumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $context), 'mobilenumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $context),
'email' => $person->getEmail(), 'email' => $person->getEmail(),
'gender' => $person->getGender(), 'gender' => $this->normalizer->normalize($person->getGender(), $format, $context),
'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context), 'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context),
]; ];