pelican-panel-mirror/app/Http/Controllers/Admin/Servers/ServerTransferController.php
Boy132 6bdd1b3ccb
Add api for server transfers (#153)
* add application api endpoint to start server transfer

* add basics for "cancel transfer" endpoint

* wire up wings cancel

* lint
2024-05-15 07:37:56 -07:00

45 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Servers;
use App\Http\Controllers\Controller;
use App\Models\Server;
use App\Services\Servers\TransferServerService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Prologue\Alerts\AlertsMessageBag;
class ServerTransferController extends Controller
{
/**
* ServerTransferController constructor.
*/
public function __construct(
private AlertsMessageBag $alert,
private TransferServerService $transferServerService,
) {
}
/**
* Starts a transfer of a server to a new node.
*
* @throws \Throwable
*/
public function transfer(Request $request, Server $server): RedirectResponse
{
$validatedData = $request->validate([
'node_id' => 'required|exists:nodes,id',
'allocation_id' => 'required|bail|unique:servers|exists:allocations,id',
'allocation_additional' => 'nullable',
]);
if ($this->transferServerService->handle($server, $validatedData)) {
$this->alert->success(trans('admin/server.alerts.transfer_started'))->flash();
} else {
$this->alert->danger(trans('admin/server.alerts.transfer_not_viable'))->flash();
}
return redirect()->route('admin.servers.view.manage', $server->id);
}
}