api resource refactoring part 5

This commit is contained in:
Peter Papp
2021-08-27 13:02:28 +02:00
parent 7984ce3ef1
commit 4304fb1ddb
14 changed files with 123 additions and 75 deletions
+1 -2
View File
@@ -147,8 +147,7 @@ class User extends Authenticatable implements MustVerifyEmail
public function favouriteFolders(): BelongsToMany
{
return $this->belongsToMany(Folder::class, 'favourite_folder', 'user_id', 'folder_id', 'id', 'id')
->where('team_folder', false)
->with('shared:token,id,item_id,permission,is_protected,expire_in');
->where('team_folder', false);
}
/**
+2 -9
View File
@@ -1,6 +1,7 @@
<?php
namespace App\Users\Resources;
use Domain\Folders\Resources\FolderCollection;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
@@ -50,15 +51,7 @@ class UserResource extends JsonResource
],
],
],
'favourites' => [
'data' => [
'id' => $this->id,
'type' => 'favourite_folders',
'attributes' => [
'folders' => $this->favouriteFolders->makeHidden(['pivot']),
],
],
],
'favourites' => new FolderCollection($this->favouriteFolders),
],
],
];
@@ -32,8 +32,9 @@ class BrowseTrashContentController
// Collect folders and files to single array
return [
'content' => collect([$folders, $files])->collapse(),
'folder' => $requestedFolder,
'folders' => new FolderCollection($folders),
'files' => new FilesCollection($files),
'root' => $requestedFolder,
];
}
@@ -43,6 +43,17 @@ class FileResource extends JsonResource
$this->mergeWhen($this->shared, fn() => [
'shared' => new ShareResource($this->shared),
]),
$this->mergeWhen($this->parent, fn() => [
'parent' => [
'data' => [
'type' => 'folder',
'id' => $this->parent->id,
'attributes' => [
'name' => $this->parent->name,
],
],
],
]),
]
],
];
@@ -43,6 +43,17 @@ class FolderResource extends JsonResource
$this->mergeWhen($this->shared, fn() => [
'shared' => new ShareResource($this->shared),
]),
$this->mergeWhen($this->parent, fn() => [
'parent' => [
'data' => [
'type' => 'folder',
'id' => $this->parent->id,
'attributes' => [
'name' => $this->parent->name,
],
],
],
]),
],
],
];