diff --git a/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifier.php b/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifier.php index d851535b6..a6840f285 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifier.php +++ b/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifier.php @@ -15,6 +15,7 @@ use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\PersonIdentifier\Validator\UniqueIdentifierConstraint; use Chill\PersonBundle\PersonIdentifier\Validator\ValidIdentifierConstraint; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation as Serializer; #[ORM\Entity] #[ORM\Table(name: 'chill_person_identifier')] @@ -22,11 +23,13 @@ use Doctrine\ORM\Mapping as ORM; #[ORM\UniqueConstraint(name: 'chill_person_identifier_unique_person_definition', columns: ['definition_id', 'person_id'])] #[UniqueIdentifierConstraint] #[ValidIdentifierConstraint] +#[Serializer\DiscriminatorMap('type', ['person_identifier' => PersonIdentifier::class])] class PersonIdentifier { #[ORM\Id] #[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)] #[ORM\GeneratedValue] + #[Serializer\Groups(['read'])] private ?int $id = null; #[ORM\ManyToOne(targetEntity: Person::class)] @@ -34,6 +37,7 @@ class PersonIdentifier private ?Person $person = null; #[ORM\Column(name: 'value', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])] + #[Serializer\Groups(['read'])] private array $value = []; #[ORM\Column(name: 'canonical', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])] @@ -42,6 +46,7 @@ class PersonIdentifier public function __construct( #[ORM\ManyToOne(targetEntity: PersonIdentifierDefinition::class)] #[ORM\JoinColumn(name: 'definition_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')] + #[Serializer\Groups(['read'])] private PersonIdentifierDefinition $definition, ) {} diff --git a/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php b/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php index 392125b23..8b60c7814 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php +++ b/src/Bundle/ChillPersonBundle/Entity/Identifier/PersonIdentifierDefinition.php @@ -13,14 +13,17 @@ namespace Chill\PersonBundle\Entity\Identifier; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation as Serializer; #[ORM\Entity] #[ORM\Table(name: 'chill_person_identifier_definition')] +#[Serializer\DiscriminatorMap('type', ['person_identifier_definition' => PersonIdentifierDefinition::class])] class PersonIdentifierDefinition { #[ORM\Id] #[ORM\Column(name: 'id', type: Types::INTEGER)] #[ORM\GeneratedValue] + #[Serializer\Groups(['read'])] private ?int $id = null; #[ORM\Column(name: 'active', type: Types::BOOLEAN, nullable: false, options: ['default' => true])] @@ -30,6 +33,7 @@ class PersonIdentifierDefinition #[ORM\Column(name: 'label', type: Types::JSON, nullable: false, options: ['default' => '[]'])] private array $label, #[ORM\Column(name: 'engine', type: Types::STRING, length: 100)] + #[Serializer\Groups(['read'])] private string $engine, #[ORM\Column(name: 'is_searchable', type: Types::BOOLEAN, options: ['default' => false])] private bool $isSearchable = false, diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index 2661b1f25..2dcc5bdd9 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -69,6 +69,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf 'gender' => $this->normalizer->normalize($person->getGender(), $format, $context), 'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context), 'personId' => $this->personIdRendering->renderPersonId($person), + 'identifiers' => $this->normalizer->normalize($person->getIdentifiers(), $format, $context), ]; if (\in_array('minimal', $groups, true) && 1 === \count($groups)) { diff --git a/src/Bundle/ChillPersonBundle/Tests/PersonIdentifier/Normalizer/PersonIdentifierWorkerNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/PersonIdentifier/Normalizer/PersonIdentifierWorkerNormalizerTest.php index ec69ccf96..c54d360d3 100644 --- a/src/Bundle/ChillPersonBundle/Tests/PersonIdentifier/Normalizer/PersonIdentifierWorkerNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/PersonIdentifier/Normalizer/PersonIdentifierWorkerNormalizerTest.php @@ -120,7 +120,7 @@ class PersonIdentifierWorkerNormalizerTest extends TestCase 'engine' => 'string', 'label' => ['en' => 'SSN'], 'isActive' => false, - 'presence' => 'ON_EDIT' + 'presence' => 'ON_EDIT', ], $normalized); }