]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/EpisodeController.php
basic channel crew
[alttp.git] / app / Http / Controllers / EpisodeController.php
index 6de7d676a496c6b6ee6aaa89ccff01d9540a5b42..1a407a184e97039738e4b3743f888fec05a3f924 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Models\Channel;
 use App\Models\Episode;
 use Carbon\Carbon;
 use Illuminate\Http\Request;
@@ -9,6 +10,40 @@ use Illuminate\Http\Request;
 class EpisodeController extends Controller
 {
 
+       public function addRestream(Request $request, Episode $episode) {
+               $this->authorize('addRestream', $episode);
+               $validatedData = $request->validate([
+                       'channel_id' => 'numeric|exists:App\Models\Channel,id',
+               ]);
+
+               $channel = Channel::find($validatedData['channel_id']);
+               $this->authorize('addEpisode', $channel);
+
+               foreach ($episode->channels as $c) {
+                       if ($c->id == $channel->id) {
+                               throw new \Exception('channel already exists on episode');
+                       }
+               }
+
+               $episode->channels()->attach($channel);
+
+               return $episode->load('channels')->toJson();
+       }
+
+       public function removeRestream(Request $request, Episode $episode) {
+               $this->authorize('removeRestream', $episode);
+               $validatedData = $request->validate([
+                       'channel_id' => 'numeric|exists:App\Models\Channel,id',
+               ]);
+
+               $channel = Channel::find($validatedData['channel_id']);
+               $this->authorize('removeEpisode', $channel);
+
+               $episode->channels()->detach($channel);
+
+               return $episode->load('channels')->toJson();
+       }
+
        public function search(Request $request) {
                $validatedData = $request->validate([
                        'after' => 'nullable|date',