- 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.
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Actions\ProductIncos;
|
|
|
|
use App\Enums\ProductIncoSyncStatus;
|
|
use App\Models\ProductInco;
|
|
|
|
final readonly class SyncProductIncoOutput
|
|
{
|
|
public function __construct(
|
|
public ProductIncoSyncStatus $status,
|
|
public ?ProductInco $inco = null,
|
|
public ?string $errorMessage = null,
|
|
) {
|
|
}
|
|
|
|
public static function success(ProductInco $inco): self
|
|
{
|
|
return new self(
|
|
status: ProductIncoSyncStatus::SUCCESS,
|
|
inco: $inco,
|
|
);
|
|
}
|
|
|
|
public static function notAssociated(): self
|
|
{
|
|
return new self(
|
|
status: ProductIncoSyncStatus::NOT_ASSOCIATED,
|
|
errorMessage: 'Product does not have an associated INCO sheet to sync.',
|
|
);
|
|
}
|
|
|
|
public static function notFoundOnArcadia(int $noArt): self
|
|
{
|
|
return new self(
|
|
status: ProductIncoSyncStatus::NOT_FOUND_ON_ARCADIA,
|
|
errorMessage: sprintf('INCO sheet #%d was not found on Arcadia API.', $noArt),
|
|
);
|
|
}
|
|
|
|
public static function apiError(string $errorMessage): self
|
|
{
|
|
return new self(
|
|
status: ProductIncoSyncStatus::API_ERROR,
|
|
errorMessage: $errorMessage,
|
|
);
|
|
}
|
|
}
|