forked from koel/koel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support playlist folders (closes koel#1476)
- Loading branch information
Showing
78 changed files
with
1,494 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V6\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\API\PlaylistStoreRequest; | ||
use App\Http\Requests\API\PlaylistUpdateRequest; | ||
use App\Http\Resources\PlaylistResource; | ||
use App\Models\Playlist; | ||
use App\Models\User; | ||
use App\Services\PlaylistService; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Support\Arr; | ||
|
||
class PlaylistController extends Controller | ||
{ | ||
/** @param User $user */ | ||
public function __construct(private PlaylistService $playlistService, private ?Authenticatable $user) | ||
{ | ||
} | ||
|
||
public function index() | ||
{ | ||
return PlaylistResource::collection($this->user->playlists); | ||
} | ||
|
||
public function store(PlaylistStoreRequest $request) | ||
{ | ||
$playlist = $this->playlistService->createPlaylist( | ||
$request->name, | ||
$this->user, | ||
Arr::wrap($request->songs), | ||
$request->rules | ||
); | ||
|
||
return PlaylistResource::make($playlist); | ||
} | ||
|
||
public function update(PlaylistUpdateRequest $request, Playlist $playlist) | ||
{ | ||
$this->authorize('own', $playlist); | ||
|
||
return PlaylistResource::make( | ||
$this->playlistService->updatePlaylist( | ||
$playlist, | ||
$request->name, | ||
Arr::wrap($request->rules) | ||
) | ||
); | ||
} | ||
|
||
public function destroy(Playlist $playlist) | ||
{ | ||
$this->authorize('own', $playlist); | ||
|
||
$playlist->delete(); | ||
|
||
return response()->noContent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V6\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Controllers\V6\Requests\PlaylistFolderStoreRequest; | ||
use App\Http\Controllers\V6\Requests\PlaylistFolderUpdateRequest; | ||
use App\Http\Resources\PlaylistFolderResource; | ||
use App\Models\PlaylistFolder; | ||
use App\Models\User; | ||
use App\Services\PlaylistFolderService; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
class PlaylistFolderController extends Controller | ||
{ | ||
/** @param User $user */ | ||
public function __construct(private PlaylistFolderService $service, private ?Authenticatable $user) | ||
{ | ||
} | ||
|
||
public function store(PlaylistFolderStoreRequest $request) | ||
{ | ||
return PlaylistFolderResource::make($this->service->createFolder($this->user, $request->name)); | ||
} | ||
|
||
public function update(PlaylistFolder $playlistFolder, PlaylistFolderUpdateRequest $request) | ||
{ | ||
$this->authorize('own', $playlistFolder); | ||
|
||
return PlaylistFolderResource::make($this->service->updateFolder($playlistFolder, $request->name)); | ||
} | ||
|
||
public function destroy(PlaylistFolder $playlistFolder) | ||
{ | ||
$this->authorize('own', $playlistFolder); | ||
|
||
$playlistFolder->delete(); | ||
|
||
return response()->noContent(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/Http/Controllers/V6/API/PlaylistFolderPlaylistController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V6\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Controllers\V6\Requests\PlaylistFolderPlaylistDestroyRequest; | ||
use App\Http\Controllers\V6\Requests\PlaylistFolderPlaylistStoreRequest; | ||
use App\Models\PlaylistFolder; | ||
use App\Services\PlaylistFolderService; | ||
use Illuminate\Support\Arr; | ||
|
||
class PlaylistFolderPlaylistController extends Controller | ||
{ | ||
public function __construct(private PlaylistFolderService $service) | ||
{ | ||
} | ||
|
||
public function store(PlaylistFolder $playlistFolder, PlaylistFolderPlaylistStoreRequest $request) | ||
{ | ||
$this->authorize('own', $playlistFolder); | ||
|
||
$this->service->addPlaylistsToFolder($playlistFolder, Arr::wrap($request->playlists)); | ||
|
||
return response()->noContent(); | ||
} | ||
|
||
public function destroy(PlaylistFolder $playlistFolder, PlaylistFolderPlaylistDestroyRequest $request) | ||
{ | ||
$this->authorize('own', $playlistFolder); | ||
|
||
$this->service->movePlaylistsToRootLevel(Arr::wrap($request->playlists)); | ||
|
||
return response()->noContent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/Http/Controllers/V6/Requests/PlaylistFolderPlaylistDestroyRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V6\Requests; | ||
|
||
use App\Http\Requests\API\Request; | ||
use App\Models\Playlist; | ||
use App\Rules\AllPlaylistsBelongToUser; | ||
use Illuminate\Validation\Rule; | ||
|
||
/** | ||
* @property-read array<int>|int $playlists | ||
*/ | ||
class PlaylistFolderPlaylistDestroyRequest extends Request | ||
{ | ||
/** @return array<mixed> */ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'playlists' => ['required', 'array', new AllPlaylistsBelongToUser($this->user())], | ||
'playlists.*' => [Rule::exists(Playlist::class, 'id')], | ||
]; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/Http/Controllers/V6/Requests/PlaylistFolderPlaylistStoreRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V6\Requests; | ||
|
||
use App\Http\Requests\API\Request; | ||
use App\Models\Playlist; | ||
use App\Rules\AllPlaylistsBelongToUser; | ||
use Illuminate\Validation\Rule; | ||
|
||
/** | ||
* @property-read array<int>|int $playlists | ||
*/ | ||
class PlaylistFolderPlaylistStoreRequest extends Request | ||
{ | ||
/** @return array<mixed> */ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'playlists' => ['required', 'array', new AllPlaylistsBelongToUser($this->user())], | ||
'playlists.*' => [Rule::exists(Playlist::class, 'id')], | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Http/Controllers/V6/Requests/PlaylistFolderStoreRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V6\Requests; | ||
|
||
use App\Http\Requests\API\Request; | ||
|
||
/** | ||
* @property-read string $name | ||
*/ | ||
class PlaylistFolderStoreRequest extends Request | ||
{ | ||
/** @return array<mixed> */ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'name' => 'required|string|max:191', | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Http/Controllers/V6/Requests/PlaylistFolderUpdateRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V6\Requests; | ||
|
||
use App\Http\Requests\API\Request; | ||
|
||
/** | ||
* @property-read string $name | ||
*/ | ||
class PlaylistFolderUpdateRequest extends Request | ||
{ | ||
/** @return array<mixed> */ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'name' => 'required|string|max:191', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use App\Models\PlaylistFolder; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class PlaylistFolderResource extends JsonResource | ||
{ | ||
public function __construct(private PlaylistFolder $folder) | ||
{ | ||
parent::__construct($folder); | ||
} | ||
|
||
/** @return array<mixed> */ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'type' => 'playlist_folders', | ||
'id' => $this->folder->id, | ||
'name' => $this->folder->name, | ||
'user_id' => $this->folder->user_id, | ||
'created_at' => $this->folder->created_at, | ||
]; | ||
} | ||
} |
Oops, something went wrong.