2022-08-10 14:56:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
|
|
|
use App\Models\Playlist;
|
2024-03-27 09:53:05 +00:00
|
|
|
use App\Models\User;
|
2022-08-10 14:56:01 +00:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
class PlaylistResource extends JsonResource
|
|
|
|
{
|
2024-01-25 16:21:26 +00:00
|
|
|
public const JSON_STRUCTURE = [
|
|
|
|
'type',
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'folder_id',
|
|
|
|
'user_id',
|
|
|
|
'is_smart',
|
|
|
|
'rules',
|
|
|
|
'own_songs_only',
|
|
|
|
'created_at',
|
|
|
|
];
|
|
|
|
|
2024-04-18 14:36:28 +00:00
|
|
|
public function __construct(private readonly Playlist $playlist)
|
2022-08-10 14:56:01 +00:00
|
|
|
{
|
|
|
|
parent::__construct($playlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return array<mixed> */
|
|
|
|
public function toArray($request): array
|
|
|
|
{
|
2024-03-27 09:53:05 +00:00
|
|
|
/** @var User $user */
|
|
|
|
$user = $request->user() ?? $this->playlist->user;
|
|
|
|
|
2022-08-10 14:56:01 +00:00
|
|
|
return [
|
|
|
|
'type' => 'playlists',
|
|
|
|
'id' => $this->playlist->id,
|
|
|
|
'name' => $this->playlist->name,
|
2024-03-27 09:53:05 +00:00
|
|
|
'folder_id' => $this->playlist->getFolderId($user),
|
2022-08-10 14:56:01 +00:00
|
|
|
'user_id' => $this->playlist->user_id,
|
|
|
|
'is_smart' => $this->playlist->is_smart,
|
2024-01-25 16:21:26 +00:00
|
|
|
'is_collaborative' => $this->playlist->is_collaborative,
|
2022-08-10 14:56:01 +00:00
|
|
|
'rules' => $this->playlist->rules,
|
2024-02-24 15:37:01 +00:00
|
|
|
'cover' => $this->playlist->cover,
|
2024-01-12 14:41:02 +00:00
|
|
|
'own_songs_only' => $this->playlist->own_songs_only,
|
2022-08-10 14:56:01 +00:00
|
|
|
'created_at' => $this->playlist->created_at,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|