added folder resource

This commit is contained in:
Peter Papp
2021-08-26 15:06:39 +02:00
parent bee7352b28
commit f5f2179145
9 changed files with 157 additions and 19 deletions
-17
View File
@@ -48,7 +48,6 @@ class Folder extends Model
protected $appends = [
'items',
'trashed_items',
'type',
];
protected $casts = [
@@ -74,11 +73,6 @@ class Folder extends Model
return FolderFactory::new();
}
public function getTypeAttribute(): string
{
return 'folder';
}
/**
* Index folder
*/
@@ -122,17 +116,6 @@ class Folder extends Model
return $folders + $files;
}
/**
* Format created at date reformat
*/
public function getCreatedAtAttribute(): string
{
return format_date(
set_time_by_user_timezone($this->attributes['created_at']),
__t('time')
);
}
/**
* Format deleted at date reformat
*/
@@ -0,0 +1,16 @@
<?php
namespace Domain\Folders\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class FolderCollection extends ResourceCollection
{
public $collects = FolderResource::class;
public function toArray($request): array
{
return [
'data' => $this->collection,
];
}
}
@@ -0,0 +1,57 @@
<?php
namespace Domain\Folders\Resources;
use Domain\Teams\Resources\TeamInvitationsCollection;
use Domain\Teams\Resources\TeamMembersCollection;
use Illuminate\Http\Resources\Json\JsonResource;
class FolderResource extends JsonResource
{
public function toArray($request): array
{
return [
'data' => [
'id' => $this->id,
'type' => 'folder',
'attributes' => [
'name' => $this->name,
'color' => $this->color,
'emoji' => $this->emoji,
'isTeamFolder' => $this->team_folder,
'items' => $this->items,
'trashed_items' => $this->trashed_items,
'updated_at' => format_date(
set_time_by_user_timezone($this->updated_at), __t('time')
),
'created_at' => format_date(
set_time_by_user_timezone($this->created_at), __t('time')
),
],
'relationships' => [
$this->mergeWhen($this->teamMembers, fn () => [
'members' => new TeamMembersCollection($this->teamMembers),
]),
$this->mergeWhen($this->teamInvitations, fn () => [
'invitations' => new TeamInvitationsCollection($this->teamInvitations),
]),
$this->mergeWhen($this->shared, fn () => [
'shared' => [
'data' => [
'id' => $this->shared->id,
'type' => 'shared',
'attributes' => [
'expire_in' => $this->shared->expire_in,
'link' => $this->shared->link,
'permission' => $this->shared->permission,
'protected' => $this->shared->protected,
'token' => $this->shared->token,
],
],
],
]),
],
],
];
}
}