mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Controllers\List\Playlist;
|
|
|
|
use App\Actions\Http\Api\List\Playlist\Track\DestroyTrackAction;
|
|
use App\Actions\Http\Api\List\Playlist\Track\StoreTrackAction;
|
|
use App\Actions\Http\Api\List\Playlist\Track\UpdateTrackAction;
|
|
use App\GraphQL\Controllers\BaseController;
|
|
use App\GraphQL\Definition\Mutations\Models\List\Playlist\Track\CreatePlaylistTrackMutation;
|
|
use App\GraphQL\Definition\Mutations\Models\List\Playlist\Track\UpdatePlaylistTrackMutation;
|
|
use App\Models\List\Playlist;
|
|
use App\Models\List\Playlist\PlaylistTrack;
|
|
use Illuminate\Support\Arr;
|
|
|
|
/**
|
|
* @extends BaseController<PlaylistTrack>
|
|
*/
|
|
class PlaylistTrackController extends BaseController
|
|
{
|
|
/**
|
|
* Store a newly created resource.
|
|
*
|
|
* @param null $root
|
|
* @param array<string, mixed> $args
|
|
*/
|
|
public function store($root, array $args): PlaylistTrack
|
|
{
|
|
$validated = $this->validated($args, CreatePlaylistTrackMutation::class);
|
|
|
|
/** @var Playlist $playlist */
|
|
$playlist = Arr::pull($validated, 'playlist');
|
|
|
|
$action = new StoreTrackAction();
|
|
|
|
$stored = $action->store($playlist, PlaylistTrack::query(), $validated);
|
|
|
|
return $stored;
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource.
|
|
*
|
|
* @param null $root
|
|
* @param array<string, mixed> $args
|
|
*/
|
|
public function update($root, array $args): PlaylistTrack
|
|
{
|
|
$validated = $this->validated($args, UpdatePlaylistTrackMutation::class);
|
|
|
|
/** @var PlaylistTrack $track */
|
|
$track = Arr::pull($validated, self::MODEL);
|
|
|
|
$action = new UpdateTrackAction();
|
|
|
|
$updated = $action->update($track->playlist, $track, $validated);
|
|
|
|
return $updated;
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource.
|
|
*
|
|
* @param null $root
|
|
* @param array<string, mixed> $args
|
|
*/
|
|
public function destroy($root, array $args): array
|
|
{
|
|
/** @var PlaylistTrack $track */
|
|
$track = Arr::get($args, self::MODEL);
|
|
|
|
$action = new DestroyTrackAction();
|
|
|
|
$message = $action->destroy($track->playlist, $track);
|
|
|
|
return [
|
|
'message' => $message,
|
|
];
|
|
}
|
|
}
|