Add mount update and deletion services, add MountController@update and MountController@delete
This commit is contained in:
parent
77150b2551
commit
0db7debb46
6 changed files with 154 additions and 11 deletions
|
@ -2,10 +2,14 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Admin;
|
namespace Pterodactyl\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Pterodactyl\Models\Mount;
|
||||||
use Prologue\Alerts\AlertsMessageBag;
|
use Prologue\Alerts\AlertsMessageBag;
|
||||||
|
use Pterodactyl\Exceptions\DisplayException;
|
||||||
use Pterodactyl\Http\Controllers\Controller;
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
use Pterodactyl\Http\Requests\Admin\MountFormRequest;
|
use Pterodactyl\Services\Mounts\MountUpdateService;
|
||||||
use Pterodactyl\Services\Mounts\MountCreationService;
|
use Pterodactyl\Services\Mounts\MountCreationService;
|
||||||
|
use Pterodactyl\Services\Mounts\MountDeletionService;
|
||||||
|
use Pterodactyl\Http\Requests\Admin\MountFormRequest;
|
||||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||||
|
|
||||||
class MountController extends Controller
|
class MountController extends Controller
|
||||||
|
@ -21,25 +25,41 @@ class MountController extends Controller
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Locations\LocationCreationService
|
* @var \Pterodactyl\Services\Mounts\MountCreationService
|
||||||
*/
|
*/
|
||||||
protected $creationService;
|
protected $creationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Mounts\MountDeletionService
|
||||||
|
*/
|
||||||
|
protected $deletionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Mounts\MountUpdateService
|
||||||
|
*/
|
||||||
|
protected $updateService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MountController constructor.
|
* MountController constructor.
|
||||||
*
|
*
|
||||||
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||||
* @param \Pterodactyl\Services\Mounts\MountCreationService $creationService
|
* @param \Pterodactyl\Services\Mounts\MountCreationService $creationService
|
||||||
|
* @param \Pterodactyl\Services\Mounts\MountDeletionService $deletionService
|
||||||
|
* @param \Pterodactyl\Services\Mounts\MountUpdateService $updateService
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AlertsMessageBag $alert,
|
AlertsMessageBag $alert,
|
||||||
MountRepository $repository,
|
MountRepository $repository,
|
||||||
MountCreationService $creationService
|
MountCreationService $creationService,
|
||||||
|
MountDeletionService $deletionService,
|
||||||
|
MountUpdateService $updateService
|
||||||
) {
|
) {
|
||||||
$this->alert = $alert;
|
$this->alert = $alert;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->creationService = $creationService;
|
$this->creationService = $creationService;
|
||||||
|
$this->deletionService = $deletionService;
|
||||||
|
$this->updateService = $updateService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +102,48 @@ class MountController extends Controller
|
||||||
$mount = $this->creationService->handle($request->normalize());
|
$mount = $this->creationService->handle($request->normalize());
|
||||||
$this->alert->success('Mount was created successfully.')->flash();
|
$this->alert->success('Mount was created successfully.')->flash();
|
||||||
|
|
||||||
//return redirect()->route('admin.mounts.view', $mount->id);
|
return redirect()->route('admin.mounts.view', $mount->id);
|
||||||
return redirect()->route('admin.mounts');
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle request to update or delete location.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Http\Requests\Admin\MountFormRequest $request
|
||||||
|
* @param \Pterodactyl\Models\Mount $mount
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function update(MountFormRequest $request, Mount $mount)
|
||||||
|
{
|
||||||
|
if ($request->input('action') === 'delete') {
|
||||||
|
return $this->delete($mount);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->updateService->handle($mount->id, $request->normalize());
|
||||||
|
$this->alert->success('Mount was updated successfully.')->flash();
|
||||||
|
|
||||||
|
return redirect()->route('admin.mounts.view', $mount->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a location from the system.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Models\Mount $mount
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function delete(Mount $mount)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->deletionService->handle($mount->id);
|
||||||
|
|
||||||
|
return redirect()->route('admin.mounts');
|
||||||
|
} catch (DisplayException $ex) {
|
||||||
|
$this->alert->danger($ex->getMessage())->flash();
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('admin.mounts.view', $mount->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
app/Services/Mounts/MountDeletionService.php
Normal file
40
app/Services/Mounts/MountDeletionService.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Services\Mounts;
|
||||||
|
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
use Pterodactyl\Models\Mount;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||||
|
|
||||||
|
class MountDeletionService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MountDeletionService constructor.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(MountRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an existing location.
|
||||||
|
*
|
||||||
|
* @param int|\Pterodactyl\Models\Mount $mount
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
public function handle($mount)
|
||||||
|
{
|
||||||
|
$mount = ($mount instanceof Mount) ? $mount->id : $mount;
|
||||||
|
|
||||||
|
Assert::integerish($mount, 'First argument passed to handle must be numeric or an instance of ' . Mount::class . ', received %s.');
|
||||||
|
|
||||||
|
return $this->repository->delete($mount);
|
||||||
|
}
|
||||||
|
}
|
41
app/Services/Mounts/MountUpdateService.php
Normal file
41
app/Services/Mounts/MountUpdateService.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Services\Mounts;
|
||||||
|
|
||||||
|
use Pterodactyl\Models\Mount;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||||
|
|
||||||
|
class MountUpdateService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MountUpdateService constructor.
|
||||||
|
*
|
||||||
|
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||||
|
*/
|
||||||
|
public function __construct(MountRepository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing location.
|
||||||
|
*
|
||||||
|
* @param int|\Pterodactyl\Models\Mount $mount
|
||||||
|
* @param array $data
|
||||||
|
* @return \Pterodactyl\Models\Mount
|
||||||
|
*
|
||||||
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
|
*/
|
||||||
|
public function handle($mount, array $data)
|
||||||
|
{
|
||||||
|
$mount = ($mount instanceof Mount) ? $mount->id : $mount;
|
||||||
|
|
||||||
|
return $this->repository->update($mount, $data);
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,8 +47,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ $mount->id }}</code></td>
|
<td><code>{{ $mount->id }}</code></td>
|
||||||
<td><a href="{{ route('admin.mounts.view', $mount->id) }}">{{ $mount->name }}</a></td>
|
<td><a href="{{ route('admin.mounts.view', $mount->id) }}">{{ $mount->name }}</a></td>
|
||||||
<td>{{ $mount->source }}</td>
|
<td><code>{{ $mount->source }}</code></td>
|
||||||
<td>{{ $mount->target }}</td>
|
<td><code>{{ $mount->target }}</code></td>
|
||||||
<td class="text-center">{{ $mount->eggs_count }}</td>
|
<td class="text-center">{{ $mount->eggs_count }}</td>
|
||||||
<td class="text-center">{{ $mount->nodes_count }}</td>
|
<td class="text-center">{{ $mount->nodes_count }}</td>
|
||||||
<td class="text-center">{{ $mount->servers_count }}</td>
|
<td class="text-center">{{ $mount->servers_count }}</td>
|
||||||
|
|
|
@ -57,12 +57,12 @@
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="radio radio-success radio-inline">
|
<div class="radio radio-success radio-inline">
|
||||||
<input type="radio" id="pReadOnlyFalse" name="read_only" value="0" @if($mount->read_only) checked @endif>
|
<input type="radio" id="pReadOnlyFalse" name="read_only" value="0" @if(!$mount->read_only) checked @endif>
|
||||||
<label for="pReadOnlyFalse">False</label>
|
<label for="pReadOnlyFalse">False</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="radio radio-warning radio-inline">
|
<div class="radio radio-warning radio-inline">
|
||||||
<input type="radio" id="pReadOnly" name="read_only" value="1" @if(!$mount->read_only) checked @endif>
|
<input type="radio" id="pReadOnly" name="read_only" value="1" @if($mount->read_only) checked @endif>
|
||||||
<label for="pReadOnly">True</label>
|
<label for="pReadOnly">True</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -73,12 +73,12 @@
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="radio radio-success radio-inline">
|
<div class="radio radio-success radio-inline">
|
||||||
<input type="radio" id="pUserMountableFalse" name="user_mountable" value="0" @if($mount->user_mountable) checked @endif>
|
<input type="radio" id="pUserMountableFalse" name="user_mountable" value="0" @if(!$mount->user_mountable) checked @endif>
|
||||||
<label for="pUserMountableFalse">False</label>
|
<label for="pUserMountableFalse">False</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="radio radio-warning radio-inline">
|
<div class="radio radio-warning radio-inline">
|
||||||
<input type="radio" id="pUserMountable" name="user_mountable" value="1" @if(!$mount->user_mountable) checked @endif>
|
<input type="radio" id="pUserMountable" name="user_mountable" value="1" @if($mount->user_mountable) checked @endif>
|
||||||
<label for="pUserMountable">True</label>
|
<label for="pUserMountable">True</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -178,6 +178,7 @@ Route::group(['prefix' => 'mounts'], function () {
|
||||||
Route::get('/view/{mount}', 'MountController@view')->name('admin.mounts.view');
|
Route::get('/view/{mount}', 'MountController@view')->name('admin.mounts.view');
|
||||||
|
|
||||||
Route::post('/', 'MountController@create');
|
Route::post('/', 'MountController@create');
|
||||||
|
Route::patch('/view/{mount}', 'MountController@update');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue