42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Uwil\ArcadiaApiPhpClient\Repository;
|
||
|
|
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Error\ApiError;
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Hydrator\IncoCompoHydrator;
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoCompo;
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\IncoCompoId;
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiValueObject\IncoId;
|
||
|
|
use Uwil\ArcadiaKiotaOpenApiClient\ApiClient;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
final class IncoCompoApiRepository extends AbstractApiRepository implements IncoCompoRepository
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
ApiClient $apiClient,
|
||
|
|
private readonly IncoCompoHydrator $hydrator,
|
||
|
|
) {
|
||
|
|
parent::__construct($apiClient);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function find(IncoCompoId $id): IncoCompo | null | ApiError
|
||
|
|
{
|
||
|
|
return $this->findFor(new IncoId($id->value));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function findFor(IncoId $id): IncoCompo | null | ApiError
|
||
|
|
{
|
||
|
|
return $this->catchNotFound(function () use ($id): ?IncoCompo {
|
||
|
|
/** @var \Uwil\ArcadiaKiotaOpenApiClient\Models\IncoCompoItemResponse|null $response */
|
||
|
|
$response = $this->apiClient->incoSheets()->byIncoId($id->value)->composition()->get()->wait();
|
||
|
|
$composition = $response?->getComposition();
|
||
|
|
|
||
|
|
return $composition !== null ? $this->hydrator->toDto($composition) : null;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|