]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/ApplicationController.php
add myustery circus link
[alttp.git] / app / Http / Controllers / ApplicationController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Events\ApplicationChanged;
6 use App\Events\ApplicationRemoved;
7 use App\Models\Application;
8 use App\Models\Participant;
9 use App\Models\Protocol;
10 use Illuminate\Http\Request;
11
12 class ApplicationController extends Controller
13 {
14
15         public function accept(Request $request, Application $application) {
16                 $this->authorize('accept', $application);
17
18                 $participant = Participant::firstOrCreate([
19                         'tournament_id' => $application->tournament_id,
20                         'user_id' => $application->user_id,
21                 ]);
22                 $participant->makeRunner();
23
24                 $application->delete();
25                 ApplicationRemoved::dispatch($application->id, $application->tournament_id);
26
27                 Protocol::applicationAccepted($application->tournament, $application, $request->user());
28
29                 return $participant->toJson();
30         }
31
32         public function reject(Request $request, Application $application) {
33                 $this->authorize('reject', $application);
34
35                 $application->denied = true;
36                 $application->save();
37                 ApplicationChanged::dispatch($application);
38
39                 Protocol::applicationRejected($application->tournament, $application, $request->user());
40
41                 return $application->toJson();
42         }
43
44 }