add endoint /api/1.0/search.json?q=xxx with fake data

See https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/136
This commit is contained in:
2021-05-07 19:11:10 +02:00
parent 038d7ad2e1
commit 7a1ad24f0e
16 changed files with 261 additions and 25 deletions

View File

@@ -25,7 +25,7 @@ use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Chill\PersonBundle\Repository\PersonRepository;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
/**
* Serialize a Person entity
@@ -41,25 +41,45 @@ class PersonNormalizer implements
protected PersonRepository $repository;
private ChillEntityRenderExtension $render;
public const GET_PERSON = 'get_person';
public function __construct(PersonRepository $repository)
public function __construct(PersonRepository $repository, ChillEntityRenderExtension $render)
{
$this->repository = $repository;
$this->render = $render;
}
public function normalize($person, string $format = null, array $context = array())
{
/** @var Person $person */
return [
'id' => $person->getId(),
'type' => 'person',
'person_id' => $person->getId(),
'text' => $this->render->renderString($person),
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate()),
'center' => $this->normalizer->normalize($person->getCenter())
'center' => $this->normalizer->normalize($person->getCenter()),
'phonenumber' => $person->getPhonenumber(),
'mobilenumber' => $person->getMobilenumber(),
'altNames' => $this->normalizeAltNames($person->getAltNames())
];
}
protected function normalizeAltNames($altNames): array
{
$r = [];
foreach ($altNames as $n) {
$r[] = [ 'key' => $n->getKey(), 'label' => $n->getLabel() ];
}
return $r;
}
public function denormalize($data, string $type, string $format = null, array $context = []): Person
{
if ($context[self::GET_PERSON] ?? true) {