1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Http\Controllers\InterOp;
7
8use App\Http\Controllers\Controller;
9use App\Models\User;
10
11class UserGroupsController extends Controller
12{
13 public function update($userId, $groupId)
14 {
15 User::findOrFail($userId)->addToGroup(
16 app('groups')->byIdOrFail($groupId),
17 get_arr(request()->input('playmodes'), 'get_string'),
18 $this->getActor(),
19 );
20
21 return response(null, 204);
22 }
23
24 public function destroy($userId, $groupId)
25 {
26 User::findOrFail($userId)->removeFromGroup(
27 app('groups')->byIdOrFail($groupId),
28 $this->getActor(),
29 );
30
31 return response(null, 204);
32 }
33
34 public function setDefault($userId, $groupId)
35 {
36 User::findOrFail($userId)->setDefaultGroup(
37 app('groups')->byIdOrFail($groupId),
38 $this->getActor(),
39 );
40
41 return response(null, 204);
42 }
43
44 private function getActor(): ?User
45 {
46 $actorId = request()->input('actor_id');
47
48 return present($actorId) ? User::findOrFail($actorId) : null;
49 }
50}