feat : ajout du bundle Malio ednotif pour l'utilisation des WS

This commit is contained in:
2026-01-23 17:14:45 +01:00
parent d32b607dda
commit f881488549
14 changed files with 581 additions and 378 deletions

View File

@@ -0,0 +1,70 @@
<?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;
}
}