You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
962 B
30 lines
962 B
<?php
|
|
|
|
namespace App\Domains\Channel\Actions\Api;
|
|
|
|
use App\Domains\Channel\DTOs\Api\EndpointUrlDTO;
|
|
use App\Domains\Channel\Models\ApiEndpoint;
|
|
use Exception;
|
|
|
|
class AssignEndpointUrl
|
|
{
|
|
/**
|
|
* @param EndpointUrlDTO[] $endpointToSave
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function execute(array $endpointToSave): void
|
|
{
|
|
$validateArrayDTO = array_map(fn ($endpoint) => $endpoint instanceof EndpointUrlDTO, $endpointToSave);
|
|
if (in_array(false, $validateArrayDTO)) {
|
|
throw new Exception(sprintf('Invalid parameter. to use this action, the $endpointToSave must be an array of %s', EndpointUrlDTO::class));
|
|
}
|
|
|
|
$toSave = array_map(fn (EndpointUrlDTO $endpoint) => [
|
|
'client_id' => $endpoint->clientId,
|
|
'key' => $endpoint->field,
|
|
'value' => $endpoint->endpointUrl,
|
|
], $endpointToSave);
|
|
ApiEndpoint::upsert($toSave, ['client_id', 'key']);
|
|
}
|
|
}
|
|
|