]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/UserController.php
user nicknames
[alttp.git] / app / Http / Controllers / UserController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Events\UserChanged;
6 use App\Models\User;
7 use Illuminate\Http\Request;
8
9 class UserController extends Controller
10 {
11
12         public function setLanguage(Request $request) {
13                 $user = $request->user();
14                 if (!$user) return;
15
16                 $validatedData = $request->validate([
17                         'language' => 'required|in:de,en',
18                 ]);
19
20                 $user->locale = $validatedData['language'];
21                 $user->update();
22
23                 return $user->toJson();
24         }
25
26         public function setNickname(Request $request, User $user) {
27                 $this->authorize('setNickname', $user);
28
29                 $validatedData = $request->validate([
30                         'nickname' => 'string',
31                 ]);
32
33                 $user->nickname = $validatedData['nickname'];
34                 $user->update();
35
36                 UserChanged::dispatch($user);
37
38                 return $user->toJson();
39         }
40
41         public function setStreamLink(Request $request, User $user) {
42                 $this->authorize('setStreamLink', $user);
43
44                 $validatedData = $request->validate([
45                         'stream_link' => 'required|url',
46                 ]);
47
48                 $user->stream_link = $validatedData['stream_link'];
49                 $user->update();
50
51                 UserChanged::dispatch($user);
52
53                 return $user->toJson();
54         }
55
56         public function single(Request $request, $id) {
57                 $user = User::findOrFail($id);
58                 $this->authorize('view', $user);
59                 $user->load('participation');
60                 $user->load('participation.tournament');
61                 $user->loadCount('round_first');
62                 $user->loadCount('round_second');
63                 $user->loadCount('round_third');
64                 $user->loadCount('tournament_first');
65                 $user->loadCount('tournament_second');
66                 $user->loadCount('tournament_third');
67                 return $user->toJson();
68         }
69
70 }