it_get_team_folders_shared_with_another_user

This commit is contained in:
Peter Papp
2021-08-24 17:24:36 +02:00
parent 78bf913d92
commit bcfe813e1e
3 changed files with 91 additions and 4 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace Domain\Teams\Controllers;
use Domain\Files\Models\File;
use Domain\Folders\Models\Folder;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Str;
class BrowseSharedWithMeController
{
public function __invoke($id)
{
$rootId = Str::isUuid($id) ? $id : null;
$requestedFolder = Str::isUuid($id) ? Folder::findOrFail($rootId) : null;
if ($rootId) {
$folders = Folder::with(['parent:id,name', 'shared:token,id,item_id,permission,is_protected,expire_in'])
->where('id', $id)
->sortable()
->get();
$files = File::with(['parent:id,name', 'shared:token,id,item_id,permission,is_protected,expire_in'])
->where('folder_id', $id)
->sortable()
->get();
}
if (! $rootId) {
$folderIds = DB::table('team_folder_members')
->where('member_id', Auth::id())
->pluck('folder_id');
$folders = Folder::with(['parent:id,name', 'shared:token,id,item_id,permission,is_protected,expire_in'])
->whereIn('id', $folderIds)
->sortable()
->get();
$files = [];
}
// Collect folders and files to single array
return [
'content' => collect([$folders, $files])->collapse(),
'folder' => $requestedFolder,
];
}
}