| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #6 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
71 lines
2.5 KiB
PHP
71 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use App\ApiResource\BovinIdentification;
|
|
use App\ApiResource\PresencePeriod;
|
|
use Malio\EdnotifBundle\Bovin\Api\BovinApiInterface;
|
|
|
|
/**
|
|
* @implements ProviderInterface<null|BovinIdentification>
|
|
*/
|
|
final class BovinIdentificationProvider implements ProviderInterface
|
|
{
|
|
public function __construct(
|
|
private BovinApiInterface $bovinApi
|
|
) {}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?BovinIdentification
|
|
{
|
|
$numeroNational = (string) ($uriVariables['numeroNational'] ?? '');
|
|
if ('' === $numeroNational) {
|
|
return null;
|
|
}
|
|
|
|
$animalFileDto = $this->bovinApi->getAnimalFile(
|
|
nationalNumber: $numeroNational,
|
|
countryCode: 'FR'
|
|
);
|
|
|
|
$identificationDto = $animalFileDto->identification;
|
|
|
|
$resource = new BovinIdentification();
|
|
$resource->numeroNational = $numeroNational;
|
|
|
|
$resource->sex = $identificationDto?->sex;
|
|
$resource->breedType = $identificationDto?->breedType;
|
|
$resource->workNumber = $identificationDto?->workNumber;
|
|
|
|
$resource->birthDate = $identificationDto?->birthDate?->date?->format('Y-m-d');
|
|
$resource->birthDateCompletenessFlag = $identificationDto?->birthDate?->completenessFlag;
|
|
|
|
$resource->isFilie = $identificationDto?->isFilie;
|
|
|
|
$resource->motherNationalNumber = $identificationDto?->motherCarrier?->bovin?->nationalNumber;
|
|
$resource->motherBreedType = $identificationDto?->motherCarrier?->breedType;
|
|
|
|
$resource->fatherNationalNumber = $identificationDto?->fatherIpg?->bovin?->nationalNumber;
|
|
$resource->fatherBreedType = $identificationDto?->fatherIpg?->breedType;
|
|
|
|
$resource->birthExploitationNumber = $identificationDto?->birthExploitation?->exploitationNumber;
|
|
|
|
foreach ($animalFileDto->presencePeriods as $presencePeriodDto) {
|
|
$presencePeriod = new PresencePeriod();
|
|
|
|
$presencePeriod->entryDate = $presencePeriodDto->entry?->date?->format('Y-m-d');
|
|
$presencePeriod->entryCause = $presencePeriodDto->entry?->cause;
|
|
|
|
$presencePeriod->exitDate = $presencePeriodDto->exit?->date?->format('Y-m-d');
|
|
$presencePeriod->exitCause = $presencePeriodDto->exit?->cause;
|
|
|
|
$resource->presencePeriods[] = $presencePeriod;
|
|
}
|
|
|
|
return $resource;
|
|
}
|
|
}
|