change of the browsing functionality

This commit is contained in:
Milos Holba
2022-04-14 16:25:57 +02:00
parent d71e598758
commit ad8793ce28
3 changed files with 90 additions and 29 deletions

View File

@@ -2,7 +2,6 @@
namespace Domain\Browsing\Controllers;
use Str;
use Illuminate\Http\Request;
use Domain\Files\Models\File;
use Domain\Folders\Models\Folder;
use Illuminate\Support\Facades\Auth;
@@ -11,25 +10,40 @@ use Domain\Folders\Resources\FolderResource;
class BrowseFolderController
{
public function __invoke(
Request $request,
string $id,
): array {
$root_id = Str::isUuid($id) ? $id : null;
$folderQuery = [
'parent_id' => $root_id,
'team_folder' => false,
'user_id' => Auth::id(),
'deleted_at' => null
];
$fileQuery = [
'parent_id' => $root_id,
'user_id' => Auth::id(),
'deleted_at' => null
];
list($foldersTake, $foldersSkip, $filesTake, $filesSkip, $totalItemsCount) = getRecordsCount($folderQuery, $fileQuery);
$folders = Folder::with(['parent:id,name', 'shared:token,id,item_id,permission,is_protected,expire_in'])
->where('parent_id', $root_id)
->where('team_folder', false)
->where('user_id', Auth::id())
->where($folderQuery)
->sortable()
->skip($foldersSkip)
->take($foldersTake)
->get();
$files = File::with(['parent:id,name', 'shared:token,id,item_id,permission,is_protected,expire_in'])
->where('parent_id', $root_id)
->where('user_id', Auth::id())
->where($fileQuery)
->sortable()
->skip($filesSkip)
->take($filesTake)
->get();
list($data, $paginate, $links) = groupPaginate($request, $folders, $files);
list($data, $paginate, $links) = groupPaginate($folders, $files, $totalItemsCount);
return [
'data' => $data,