controller refactoring part 24

This commit is contained in:
Peter Papp
2021-07-21 18:46:55 +02:00
parent 54f1f4c9a8
commit 6d8a7a429c
29 changed files with 561 additions and 209 deletions

View File

@@ -3,11 +3,12 @@ namespace Domain\Folders\Controllers;
use Illuminate\Http\Response;
use Domain\Sharing\Models\Share;
use Support\Services\HelperService;
use App\Http\Controllers\Controller;
use Domain\Folders\Actions\CreateFolderAction;
use Domain\Folders\Requests\CreateFolderRequest;
use Support\Demo\Actions\FakeCreateFolderAction;
use Domain\Sharing\Actions\ProtectShareRecordAction;
use Domain\Sharing\Actions\VerifyAccessToItemAction;
/**
* Create new folder for guest user with edit permission
@@ -15,22 +16,23 @@ use Support\Demo\Actions\FakeCreateFolderAction;
class VisitorCreateFolderController extends Controller
{
public function __construct(
public HelperService $helper,
private CreateFolderAction $createFolder,
private ProtectShareRecordAction $protectShareRecord,
private VerifyAccessToItemAction $verifyAccessToItem,
private FakeCreateFolderAction $fakeCreateFolderAction,
) {
}
public function __invoke(
FakeCreateFolderAction $fakeCreateFolderAction,
CreateFolderAction $createFolder,
CreateFolderRequest $request,
Share $shared,
): Response | array {
if (is_demo_account($shared->user->email)) {
return ($fakeCreateFolderAction)($request);
return ($this->fakeCreateFolderAction)($request);
}
// Check ability to access protected share record
$this->helper->check_protected_share_record($shared);
($this->protectShareRecord)($shared);
// Check shared permission
if (is_visitor($shared)) {
@@ -38,10 +40,10 @@ class VisitorCreateFolderController extends Controller
}
// Check access to requested directory
$this->helper->check_item_access($request->parent_id, $shared);
($this->verifyAccessToItem)($request->parent_id, $shared);
// Create folder
$folder = ($createFolder)($request, $shared);
$folder = ($this->createFolder)($request, $shared);
return response($folder, 201);
}