mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-11-04 03:08:25 +00:00 
			
		
		
		
	Create gender API and adjust serialization of gender property
This commit is contained in:
		@@ -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');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -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),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user