- Added `Choices` component for dropdowns with search and multi-selection functionality. - Implemented foundational classes for service connection: - `ConnectServiceData` - `ConnectedServiceFactory` - `ConnectedServicesService` - Added `ConnectServiceForm` Livewire component for managing service connections. - Introduced shared utility traits (`HasAttributeHelpers`) and error components. - Added components for generic use: `Input` and `ListItem`.
35 lines
976 B
PHP
35 lines
976 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Factories;
|
|
|
|
use App\Data\ConnectService\ConnectServiceData;
|
|
use App\Enums\ConnectionStatus;
|
|
use App\Models\ServiceStatus;
|
|
|
|
final class ConnectedServiceFactory
|
|
{
|
|
public function createDataFromDto(ConnectServiceData $data): array
|
|
{
|
|
$result = [
|
|
'name' => $data->name,
|
|
'service_provider_id' => $data->serviceProviderId,
|
|
'service_protocol_id' => $data->serviceProtocolId,
|
|
'logo_url' => $data->logoUrl,
|
|
'slug' => $data->slug,
|
|
'service_status_id' => $data->statusId,
|
|
];
|
|
|
|
// Check if the staus is filled, if not select disconnected by default
|
|
if (null === $data->statusId) {
|
|
$status = ServiceStatus::query()
|
|
->where('name', '=', ConnectionStatus::Disconnected->value)
|
|
->pluck('id');
|
|
$result['service_status_id'] = $status[0];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|