]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/UserController.php
user nicknames
[alttp.git] / app / Http / Controllers / UserController.php
index 58d725d383b4aee9e5d8111fa329cee103b836a1..da3ebde1bf113bd18e2b56b6fee72ab23a155fd3 100644 (file)
@@ -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();
+       }
+
 }