All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
- 3 nouveaux endpoints API Platform pass-through sur /api/bovins/{inventory|returned-dossiers|presumed-exits} consommant BovinApiInterface v0.0.6
- AnimalSummaryMapper (src/Service/) factorisant le mapping DTO EDNOTIF -> ressource
- src/State/ réorganisé par domaine (Bovin/, Reception/, Shipment/, Building/, User/, System/)
- tag OpenAPI "Bovins" pour regrouper les endpoints ednotif dans Swagger
- malio/ednotif-bundle passé à v0.0.6
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| 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
- [ ] TU/TI/TF OK
- [ ] CHANGELOG modifié
Reviewed-on: #47
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
69 lines
2.0 KiB
PHP
69 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State\Bovin;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProcessorInterface;
|
|
use App\Entity\Bovine;
|
|
use Malio\EdnotifBundle\Bovin\Api\BovinApiInterface;
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
use Throwable;
|
|
|
|
final class BovineProcessor implements ProcessorInterface
|
|
{
|
|
public function __construct(
|
|
private readonly BovinApiInterface $bovinApi,
|
|
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
|
private readonly ProcessorInterface $persistProcessor,
|
|
) {}
|
|
|
|
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
|
{
|
|
if ($data instanceof Bovine && '' !== $data->getNationalNumber()) {
|
|
$this->enrichFromEdnotif($data);
|
|
}
|
|
|
|
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
|
|
}
|
|
|
|
private function enrichFromEdnotif(Bovine $bovine): void
|
|
{
|
|
try {
|
|
$animalFile = $this->bovinApi->getAnimalFile(
|
|
nationalNumber: $bovine->getNationalNumber(),
|
|
countryCode: 'FR',
|
|
);
|
|
|
|
$identification = $animalFile->identification;
|
|
if (null === $identification) {
|
|
return;
|
|
}
|
|
|
|
$bovine->setWorkNumber($identification->workNumber);
|
|
$bovine->setBirthDate($identification->birthDate?->date);
|
|
$bovine->setBreedCode($this->normalizeBreedCode($identification->breedType));
|
|
} catch (Throwable) {
|
|
// External service unavailable — persist bovine without enrichment.
|
|
}
|
|
}
|
|
|
|
private function normalizeBreedCode(mixed $breedType): ?string
|
|
{
|
|
if (null === $breedType) {
|
|
return null;
|
|
}
|
|
|
|
if (is_numeric($breedType)) {
|
|
return (string) $breedType;
|
|
}
|
|
|
|
if (is_string($breedType) && preg_match('/\d+/', $breedType, $matches)) {
|
|
return $matches[0];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|