58 lines
2.4 KiB
PHP
58 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Actions\Environments\AttachManagedService;
|
|
use App\Enums\EnvironmentAttachmentRole;
|
|
use App\Enums\ServiceType;
|
|
use App\Http\Requests\StoreEnvironmentAttachmentRequest;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Response;
|
|
|
|
class EnvironmentAttachmentController extends Controller
|
|
{
|
|
public function create(Request $request): Response
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
$application = $organisation->applications()->findOrFail($request->route('application'));
|
|
$environment = $application->environments()->findOrFail($request->route('environment'));
|
|
|
|
return inertia('environment-attachments/Create', [
|
|
'application' => $application,
|
|
'environment' => $environment,
|
|
'services' => $organisation->services()
|
|
->whereIn('type', [ServiceType::POSTGRES->value, ServiceType::VALKEY->value, ServiceType::CADDY->value])
|
|
->orderBy('name')
|
|
->get(['id', 'name', 'type', 'category']),
|
|
'roles' => array_values(EnvironmentAttachmentRole::toArray()),
|
|
]);
|
|
}
|
|
|
|
public function store(StoreEnvironmentAttachmentRequest $request): RedirectResponse
|
|
{
|
|
$organisation = Organisation::findOrFail($request->route('organisation'));
|
|
$application = $organisation->applications()->findOrFail($request->route('application'));
|
|
$environment = $application->environments()->findOrFail($request->route('environment'));
|
|
$service = $organisation->services()->findOrFail($request->integer('service_id'));
|
|
|
|
app(AttachManagedService::class)->execute(
|
|
environment: $environment,
|
|
service: $service,
|
|
role: $request->enum('role', EnvironmentAttachmentRole::class),
|
|
name: $request->filled('name') ? $request->string('name')->toString() : null,
|
|
envPrefix: $request->filled('env_prefix') ? $request->string('env_prefix')->toString() : null,
|
|
isPrimary: $request->boolean('is_primary', true),
|
|
);
|
|
|
|
return redirect()
|
|
->route('environments.show', [
|
|
'organisation' => $organisation->id,
|
|
'application' => $application->id,
|
|
'environment' => $environment->id,
|
|
])
|
|
->with('success', 'Managed service attached.');
|
|
}
|
|
}
|