diff --git a/app/Http/Requests/API/AddSongsToPlaylistRequest.php b/app/Http/Requests/API/AddSongsToPlaylistRequest.php index 26167a7d..37a185e7 100644 --- a/app/Http/Requests/API/AddSongsToPlaylistRequest.php +++ b/app/Http/Requests/API/AddSongsToPlaylistRequest.php @@ -14,8 +14,7 @@ class AddSongsToPlaylistRequest extends Request public function rules(): array { return [ - 'songs' => 'required|array', - 'songs.*' => [Rule::exists(Song::class, 'id')], + 'songs' => ['required', 'array', Rule::exists(Song::class, 'id')], ]; } } diff --git a/app/Http/Requests/API/BatchInteractionRequest.php b/app/Http/Requests/API/BatchInteractionRequest.php index 029e0d8a..452c05bc 100644 --- a/app/Http/Requests/API/BatchInteractionRequest.php +++ b/app/Http/Requests/API/BatchInteractionRequest.php @@ -2,6 +2,9 @@ namespace App\Http\Requests\API; +use App\Models\Song; +use Illuminate\Validation\Rule; + /** * @property array $songs */ @@ -11,7 +14,7 @@ class BatchInteractionRequest extends Request public function rules(): array { return [ - 'songs' => 'required|array|exists:songs,id', + 'songs' => ['required', 'array', Rule::exists(Song::class, 'id')], ]; } } diff --git a/app/Http/Requests/API/ChangeSongsVisibilityRequest.php b/app/Http/Requests/API/ChangeSongsVisibilityRequest.php index dfc67e07..a786a5c1 100644 --- a/app/Http/Requests/API/ChangeSongsVisibilityRequest.php +++ b/app/Http/Requests/API/ChangeSongsVisibilityRequest.php @@ -3,6 +3,8 @@ namespace App\Http\Requests\API; use App\Facades\License; +use App\Models\Song; +use Illuminate\Validation\Rule; /** * @property-read array $songs @@ -13,7 +15,7 @@ class ChangeSongsVisibilityRequest extends Request public function rules(): array { return [ - 'songs' => 'required|exists:songs,id', + 'songs' => ['required', 'array', Rule::exists(Song::class, 'id')], ]; } diff --git a/app/Http/Requests/API/DeleteSongsRequest.php b/app/Http/Requests/API/DeleteSongsRequest.php index 46ff7e34..5f9b0c0c 100644 --- a/app/Http/Requests/API/DeleteSongsRequest.php +++ b/app/Http/Requests/API/DeleteSongsRequest.php @@ -2,6 +2,9 @@ namespace App\Http\Requests\API; +use App\Models\Song; +use Illuminate\Validation\Rule; + /** @property-read array $songs */ class DeleteSongsRequest extends Request { @@ -9,7 +12,7 @@ class DeleteSongsRequest extends Request public function rules(): array { return [ - 'songs' => 'required|array|exists:songs,id', + 'songs' => ['required', 'array', Rule::exists(Song::class, 'id')], ]; } } diff --git a/app/Http/Requests/API/PlaylistFolderPlaylistDestroyRequest.php b/app/Http/Requests/API/PlaylistFolderPlaylistDestroyRequest.php index ccf583cd..f2a6934c 100644 --- a/app/Http/Requests/API/PlaylistFolderPlaylistDestroyRequest.php +++ b/app/Http/Requests/API/PlaylistFolderPlaylistDestroyRequest.php @@ -3,7 +3,7 @@ namespace App\Http\Requests\API; use App\Models\Playlist; -use App\Rules\AllPlaylistsBelongToUser; +use App\Rules\AllPlaylistsBelongTo; use Illuminate\Validation\Rule; /** @@ -15,8 +15,12 @@ class PlaylistFolderPlaylistDestroyRequest extends Request public function rules(): array { return [ - 'playlists' => ['required', 'array', new AllPlaylistsBelongToUser($this->user())], - 'playlists.*' => [Rule::exists(Playlist::class, 'id')], + 'playlists' => [ + 'required', + 'array', + new AllPlaylistsBelongTo($this->user()), + Rule::exists(Playlist::class, 'id'), + ], ]; } } diff --git a/app/Http/Requests/API/PlaylistFolderPlaylistStoreRequest.php b/app/Http/Requests/API/PlaylistFolderPlaylistStoreRequest.php index d11da0f2..6d7257db 100644 --- a/app/Http/Requests/API/PlaylistFolderPlaylistStoreRequest.php +++ b/app/Http/Requests/API/PlaylistFolderPlaylistStoreRequest.php @@ -3,7 +3,7 @@ namespace App\Http\Requests\API; use App\Models\Playlist; -use App\Rules\AllPlaylistsBelongToUser; +use App\Rules\AllPlaylistsBelongTo; use Illuminate\Validation\Rule; /** @@ -15,8 +15,12 @@ class PlaylistFolderPlaylistStoreRequest extends Request public function rules(): array { return [ - 'playlists' => ['required', 'array', new AllPlaylistsBelongToUser($this->user())], - 'playlists.*' => [Rule::exists(Playlist::class, 'id')], + 'playlists' => [ + 'required', + 'array', + new AllPlaylistsBelongTo($this->user()), + Rule::exists(Playlist::class, 'id'), + ], ]; } } diff --git a/app/Http/Requests/API/RemoveSongsFromPlaylistRequest.php b/app/Http/Requests/API/RemoveSongsFromPlaylistRequest.php index b1f522cc..edf8772e 100644 --- a/app/Http/Requests/API/RemoveSongsFromPlaylistRequest.php +++ b/app/Http/Requests/API/RemoveSongsFromPlaylistRequest.php @@ -2,6 +2,9 @@ namespace App\Http\Requests\API; +use App\Models\Song; +use Illuminate\Validation\Rule; + /** * @property-read array $songs */ @@ -11,7 +14,7 @@ class RemoveSongsFromPlaylistRequest extends Request public function rules(): array { return [ - 'songs' => 'required|array|exists:songs,id', + 'songs' => ['required', 'array', Rule::exists(Song::class, 'id')], ]; } } diff --git a/app/Http/Requests/API/SongUpdateRequest.php b/app/Http/Requests/API/SongUpdateRequest.php index 25c5172f..60cfa3ef 100644 --- a/app/Http/Requests/API/SongUpdateRequest.php +++ b/app/Http/Requests/API/SongUpdateRequest.php @@ -2,9 +2,12 @@ namespace App\Http\Requests\API; +use App\Models\Song; +use Illuminate\Validation\Rule; + /** - * @property array $songs - * @property array $data + * @property-read array $songs + * @property-read array $data */ class SongUpdateRequest extends Request { @@ -13,7 +16,7 @@ class SongUpdateRequest extends Request { return [ 'data' => 'required|array', - 'songs' => 'required|array|exists:songs,id', + 'songs' => ['required', 'array', Rule::exists(Song::class, 'id')], ]; } } diff --git a/app/Http/Requests/API/UpdateQueueStateRequest.php b/app/Http/Requests/API/UpdateQueueStateRequest.php index fe26f5ce..9f04901c 100644 --- a/app/Http/Requests/API/UpdateQueueStateRequest.php +++ b/app/Http/Requests/API/UpdateQueueStateRequest.php @@ -14,8 +14,7 @@ class UpdateQueueStateRequest extends Request public function rules(): array { return [ - 'songs' => 'array', - 'songs.*' => [Rule::exists(Song::class, 'id')], + 'songs' => ['array', Rule::exists(Song::class, 'id')], ]; } } diff --git a/app/Rules/AllPlaylistsBelongToUser.php b/app/Rules/AllPlaylistsBelongTo.php similarity index 91% rename from app/Rules/AllPlaylistsBelongToUser.php rename to app/Rules/AllPlaylistsBelongTo.php index 717c1dab..bf242408 100644 --- a/app/Rules/AllPlaylistsBelongToUser.php +++ b/app/Rules/AllPlaylistsBelongTo.php @@ -6,7 +6,7 @@ use App\Models\User; use Illuminate\Contracts\Validation\Rule; use Illuminate\Support\Arr; -class AllPlaylistsBelongToUser implements Rule +final class AllPlaylistsBelongTo implements Rule { public function __construct(private User $user) { diff --git a/tests/Feature/InteractionTest.php b/tests/Feature/InteractionTest.php index 24b78531..4c7353f2 100644 --- a/tests/Feature/InteractionTest.php +++ b/tests/Feature/InteractionTest.php @@ -45,7 +45,7 @@ class InteractionTest extends TestCase ]); } - public function testToggle(): void + public function testToggleLike(): void { $this->expectsEvents(SongLikeToggled::class); @@ -72,7 +72,7 @@ class InteractionTest extends TestCase ]); } - public function testToggleBatch(): void + public function testToggleLikeBatch(): void { $this->expectsEvents(SongsBatchLiked::class);