[#ED-1] Ajout des API de lecture bovin (#2)
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #2 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #2.
This commit is contained in:
68
src/Bovin/Mapper/InventoryMapper.php
Normal file
68
src/Bovin/Mapper/InventoryMapper.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Malio\EdnotifBundle\Bovin\Mapper;
|
||||
|
||||
use Malio\EdnotifBundle\Bovin\Dto\EarTagSeriesDto;
|
||||
use Malio\EdnotifBundle\Bovin\Dto\InventoryDto;
|
||||
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
|
||||
|
||||
final class InventoryMapper
|
||||
{
|
||||
use BovinNodeMappingTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly AnimalSummaryMapper $animalSummaryMapper,
|
||||
private readonly StandardResponseMapper $standardResponseMapper,
|
||||
) {}
|
||||
|
||||
public function map(object $soapResponse, ?object $unzippedMessage): InventoryDto
|
||||
{
|
||||
$standardResponse = $this->standardResponseMapper->map($soapResponse->ReponseStandard ?? null);
|
||||
|
||||
$nbBovins = $this->toNullableInt($soapResponse->ReponseSpecifique->NbBovins ?? null) ?? 0;
|
||||
|
||||
$startDate = null;
|
||||
$endDate = null;
|
||||
$includesEarTagStock = null;
|
||||
$animals = [];
|
||||
$earTagSeries = [];
|
||||
|
||||
if (is_object($unzippedMessage)) {
|
||||
$infoNode = $unzippedMessage->InformationsMessage ?? null;
|
||||
if (is_object($infoNode)) {
|
||||
$startDate = $this->toNullableDate($infoNode->DateDebut ?? null);
|
||||
$endDate = $this->toNullableDate($infoNode->DateFin ?? null);
|
||||
$includesEarTagStock = $this->toNullableBool($infoNode->StockBoucles ?? null);
|
||||
}
|
||||
|
||||
$bovinsNode = $unzippedMessage->Bovins->Bovin ?? null;
|
||||
foreach ($this->normalizeToList($bovinsNode) as $bovinNode) {
|
||||
if (!is_object($bovinNode)) {
|
||||
continue;
|
||||
}
|
||||
$animals[] = $this->animalSummaryMapper->map($bovinNode);
|
||||
}
|
||||
|
||||
$seriesNode = $unzippedMessage->Boucles->SerieBoucles ?? null;
|
||||
foreach ($this->normalizeToList($seriesNode) as $serieNode) {
|
||||
if (!is_object($serieNode)) {
|
||||
continue;
|
||||
}
|
||||
$earTagSeries[] = new EarTagSeriesDto(rawNode: $serieNode);
|
||||
}
|
||||
}
|
||||
|
||||
return new InventoryDto(
|
||||
standardResponse: $standardResponse,
|
||||
nbBovins: $nbBovins,
|
||||
startDate: $startDate,
|
||||
endDate: $endDate,
|
||||
includesEarTagStock: $includesEarTagStock,
|
||||
animals: $animals,
|
||||
earTagSeries: $earTagSeries,
|
||||
rawSoapResponse: $soapResponse,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user