X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FUserController.php;h=da3ebde1bf113bd18e2b56b6fee72ab23a155fd3;hb=82b95e7542824bcdf4f1b245559cb1c93f4eafdd;hp=58d725d383b4aee9e5d8111fa329cee103b836a1;hpb=1326baff1f13e252d9c60cae03680f70a87a17e9;p=alttp.git diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 58d725d..da3ebde 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers; +use App\Events\UserChanged; +use App\Models\User; use Illuminate\Http\Request; class UserController extends Controller @@ -21,4 +23,48 @@ class UserController extends Controller return $user->toJson(); } + public function setNickname(Request $request, User $user) { + $this->authorize('setNickname', $user); + + $validatedData = $request->validate([ + 'nickname' => 'string', + ]); + + $user->nickname = $validatedData['nickname']; + $user->update(); + + UserChanged::dispatch($user); + + return $user->toJson(); + } + + public function setStreamLink(Request $request, User $user) { + $this->authorize('setStreamLink', $user); + + $validatedData = $request->validate([ + 'stream_link' => 'required|url', + ]); + + $user->stream_link = $validatedData['stream_link']; + $user->update(); + + UserChanged::dispatch($user); + + return $user->toJson(); + } + + public function single(Request $request, $id) { + $user = User::findOrFail($id); + $this->authorize('view', $user); + $user->load('participation'); + $user->load('participation.tournament'); + $user->loadCount('round_first'); + $user->loadCount('round_second'); + $user->loadCount('round_third'); + $user->loadCount('tournament_first'); + $user->loadCount('tournament_second'); + $user->loadCount('tournament_third'); + return $user->toJson(); + } + }