-
app/Http/Controllers/Submission/ApproveStreamController.php
Open in GitHubuse App\Actions\Submission\ApproveStreamAction; use App\Models\Stream; use Illuminate\Contracts\View\View; class ApproveStreamController { public function __invoke(Stream $stream, ApproveStreamAction $approveStream): View { $approveStream->handle($stream); return view('pages.streamApproved'); } }
-
app/Actions/Submission/ApproveStreamAction.php
Open in GitHubuse App\Actions\UpdateStreamAction; use App\Console\Commands\ImportChannelsForStreamsCommand; use App\Facades\YouTube; use App\Mail\StreamApprovedMail; use App\Models\Stream; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Mail; class ApproveStreamAction { public function handle(Stream $stream): void { if ($stream->approved_at) { return; } $streamData = YouTube::video($stream->youtube_id); (new UpdateStreamAction())->handle($stream, $streamData); if (is_null($stream->channel_id)) { Artisan::call(ImportChannelsForStreamsCommand::class, ['stream' => $stream]); } $stream->update(['approved_at' => now()]); Mail::to($stream->submitted_by_email)->queue(new StreamApprovedMail($stream)); } }
-
app/Actions/UpdateStreamAction.php
Open in GitHubuse App\Models\Stream; use App\Services\YouTube\StreamData; use function tap; class UpdateStreamAction { public function handle(Stream $stream, StreamData $streamData): Stream { return tap($stream, function() use ($stream, $streamData) { $stream->update([ 'title' => $streamData->title, 'description' => $streamData->description, 'thumbnail_url' => $streamData->thumbnailUrl, 'scheduled_start_time' => $streamData->plannedStart, 'actual_start_time' => $streamData->actualStartTime, 'actual_end_time' => $streamData->actualEndTime, 'status' => $streamData->status, ]); }); } }