- Added AssociateProductIncoOutput and SyncProductIncoOutput classes to handle action results. - Updated AssociateProductInco and SyncProductInco actions to return structured output instead of raw models. - Enhanced error handling for API interactions in both actions. - Refactored ProductIncosController to utilize new output structures for better response management. - Introduced new enums for status handling in actions and queries. - Added tests for new output handling and error scenarios in Associate and Sync actions.
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Queries\ProductIncos;
|
|
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use App\Services\ArcadiaIncoService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<
|
|
* \App\Cqs\Queries\ProductIncos\GetArcadiaIncoPreviewQueryInput,
|
|
* \App\Cqs\Queries\ProductIncos\GetArcadiaIncoPreviewQueryOutput
|
|
* >
|
|
*/
|
|
final readonly class GetArcadiaIncoPreviewQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private ArcadiaIncoService $arcadiaIncoService,
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function __invoke(QueryInput $input): GetArcadiaIncoPreviewQueryOutput
|
|
{
|
|
Assert::isInstanceOf($input, GetArcadiaIncoPreviewQueryInput::class);
|
|
|
|
try {
|
|
$preview = $this->arcadiaIncoService->getPreview($input->noArt);
|
|
} catch (\RuntimeException $e) {
|
|
return GetArcadiaIncoPreviewQueryOutput::apiError($e->getMessage());
|
|
}
|
|
|
|
return $preview !== null
|
|
? GetArcadiaIncoPreviewQueryOutput::found($preview)
|
|
: GetArcadiaIncoPreviewQueryOutput::notFound();
|
|
}
|
|
}
|