X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FChannelController.php;fp=app%2FHttp%2FControllers%2FChannelController.php;h=904cb8ff81ebc0833fc7912aeae96a10edae2ef5;hb=e10222af705e3475fcea6e0b17d1c9984a62db26;hp=0000000000000000000000000000000000000000;hpb=5dc7faa01ad96732b0ea126e945f215a9d0490af;p=alttp.git diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php new file mode 100644 index 0000000..904cb8f --- /dev/null +++ b/app/Http/Controllers/ChannelController.php @@ -0,0 +1,67 @@ +validate([ + 'joinable' => 'boolean|nullable', + 'manageable' => 'boolean|nullable', + 'phrase' => 'string|nullable', + ]); + + $channels = Channel::query(); + if (isset($validatedData['joinable']) && $validatedData['joinable']) { + $channels = $channels->where('twitch_chat', '!=', ''); + } + if (isset($validatedData['manageable']) && $validatedData['manageable']) { + $user = $request->user(); + if (!$user) { + return []; + } + $channels = $channels->whereHas('crews', function (Builder $query) use ($user) { + $query->where('user_id', '=', $user->id); + }); + } + if (!empty($validatedData['phrase'])) { + $channels = $channels->where('title', 'LIKE', '%'.$validatedData['phrase'].'%') + ->orWhere('short_name', 'LIKE', '%'.$validatedData['phrase'].'%'); + } + $channels = $channels->limit(5); + return $channels->get()->toJson(); + } + + public function single(Request $request, Channel $channel) { + $this->authorize('view', $channel); + return $channel->toJson(); + } + + public function join(Request $request, Channel $channel) { + if (!$channel->twitch_chat) { + throw new \Exception('channel has no twitch chat set'); + } + $this->authorize('editRestream', $channel); + $channel->join = true; + $channel->save(); + TwitchBotCommand::join($channel->twitch_chat); + return $channel->toJson(); + } + + public function part(Request $request, Channel $channel) { + if (!$channel->twitch_chat) { + throw new \Exception('channel has no twitch chat set'); + } + $this->authorize('editRestream', $channel); + $channel->join = false; + $channel->save(); + TwitchBotCommand::part($channel->twitch_chat); + return $channel->toJson(); + } + +}