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;
|
||||
|
||||
use Pterodactyl\Models\Mount;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
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\MountDeletionService;
|
||||
use Pterodactyl\Http\Requests\Admin\MountFormRequest;
|
||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||
|
||||
class MountController extends Controller
|
||||
|
@ -21,25 +25,41 @@ class MountController extends Controller
|
|||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Locations\LocationCreationService
|
||||
* @var \Pterodactyl\Services\Mounts\MountCreationService
|
||||
*/
|
||||
protected $creationService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Mounts\MountDeletionService
|
||||
*/
|
||||
protected $deletionService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Mounts\MountUpdateService
|
||||
*/
|
||||
protected $updateService;
|
||||
|
||||
/**
|
||||
* MountController constructor.
|
||||
*
|
||||
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
||||
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||
* @param \Pterodactyl\Services\Mounts\MountCreationService $creationService
|
||||
* @param \Pterodactyl\Services\Mounts\MountDeletionService $deletionService
|
||||
* @param \Pterodactyl\Services\Mounts\MountUpdateService $updateService
|
||||
*/
|
||||
public function __construct(
|
||||
AlertsMessageBag $alert,
|
||||
MountRepository $repository,
|
||||
MountCreationService $creationService
|
||||
MountCreationService $creationService,
|
||||
MountDeletionService $deletionService,
|
||||
MountUpdateService $updateService
|
||||
) {
|
||||
$this->alert = $alert;
|
||||
$this->repository = $repository;
|
||||
$this->creationService = $creationService;
|
||||
$this->deletionService = $deletionService;
|
||||
$this->updateService = $updateService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +102,48 @@ class MountController extends Controller
|
|||
$mount = $this->creationService->handle($request->normalize());
|
||||
$this->alert->success('Mount was created successfully.')->flash();
|
||||
|
||||
//return redirect()->route('admin.mounts.view', $mount->id);
|
||||
return redirect()->route('admin.mounts');
|
||||
return redirect()->route('admin.mounts.view', $mount->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
Reference in a new issue