current folder functionality

This commit is contained in:
Peter Papp
2021-08-20 17:36:46 +02:00
parent c697f8a451
commit b5a8fe8b1a
12 changed files with 135 additions and 38 deletions

View File

@@ -12,9 +12,11 @@ class BrowseFolderContentController
public function __invoke(
Request $request,
string $id,
): Collection {
): array {
$root_id = $id === 'undefined' ? null : $id;
$requestedFolder = $root_id ? Folder::findOrFail($root_id) : null;
// Get folders and files
$folders = Folder::with(['parent:id,name', 'shared:token,id,item_id,permission,is_protected,expire_in'])
->where('parent_id', $root_id)
@@ -29,7 +31,9 @@ class BrowseFolderContentController
->get();
// Collect folders and files to single array
return collect([$folders, $files])
->collapse();
return [
'content' => collect([$folders, $files])->collapse(),
'folder' => $requestedFolder,
];
}
}

View File

@@ -3,15 +3,15 @@ namespace Domain\Browsing\Controllers;
use Domain\Files\Models\File;
use Domain\Folders\Models\Folder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
class BrowseTrashContentController
{
public function __invoke(string $id): Collection
public function __invoke(string $id): array
{
$user_id = Auth::id();
$root_id = $id === 'undefined' ? null : $id;
$requestedFolder = $root_id ? Folder::withTrashed()->findOrFail($root_id) : null;
if ($root_id) {
@@ -29,8 +29,10 @@ class BrowseTrashContentController
->get();
// Collect folders and files to single array
return collect([$folders, $files])
->collapse();
return [
'content' => collect([$folders, $files])->collapse(),
'folder' => $requestedFolder,
];
}
// Get folders and files
@@ -58,7 +60,9 @@ class BrowseTrashContentController
->get();
// Collect folders and files to single array
return collect([$folders, $files_trashed])
->collapse();
return [
'content' => collect([$folders, $files_trashed])->collapse(),
'folder' => $requestedFolder,
];
}
}

View File

@@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
* @method static whereUserId(int|string|null $id)
* @method static find(mixed $id)
* @method static where(string $string, string $user_id)
* @method static findOrFail(string $root_id)
* @property string id
* @property string user_id
* @property string parent_id