|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
/** |
|
4
|
|
|
* /src/Controller/v1/UserGroup/UsersController.php |
|
5
|
|
|
* |
|
6
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Controller\v1\UserGroup; |
|
10
|
|
|
|
|
11
|
|
|
use App\Entity\User; |
|
12
|
|
|
use App\Entity\UserGroup; |
|
13
|
|
|
use App\Resource\UserGroupResource; |
|
14
|
|
|
use App\Resource\UserResource; |
|
15
|
|
|
use App\Rest\ResponseHandler; |
|
16
|
|
|
use App\Security\RolesService; |
|
17
|
|
|
use Nelmio\ApiDocBundle\Annotation\Model; |
|
18
|
|
|
use OpenApi\Annotations as OA; |
|
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
|
20
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
23
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
24
|
|
|
use Throwable; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class UsersController |
|
28
|
|
|
* |
|
29
|
|
|
* @package App\Controller\v1\UserGroup |
|
30
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
class UsersController |
|
33
|
|
|
{ |
|
34
|
5 |
|
public function __construct( |
|
35
|
|
|
private UserResource $userResource, |
|
36
|
|
|
private ResponseHandler $responseHandler, |
|
37
|
|
|
) { |
|
38
|
5 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Endpoint action to list specified user group users. |
|
42
|
|
|
* |
|
43
|
|
|
* @OA\Tag(name="UserGroup Management") |
|
44
|
|
|
* @OA\Parameter( |
|
45
|
|
|
* name="Authorization", |
|
46
|
|
|
* in="header", |
|
47
|
|
|
* required=true, |
|
48
|
|
|
* description="Authorization header", |
|
49
|
|
|
* @OA\Schema( |
|
50
|
|
|
* type="string", |
|
51
|
|
|
* default="Bearer _your_jwt_here_", |
|
52
|
|
|
* ) |
|
53
|
|
|
* ) |
|
54
|
|
|
* @OA\Response( |
|
55
|
|
|
* response=200, |
|
56
|
|
|
* description="User group users", |
|
57
|
|
|
* @OA\Schema( |
|
58
|
|
|
* ref=@Model( |
|
59
|
|
|
* type=User::class, |
|
60
|
|
|
* groups={"User", "User.userGroups", "User.roles", "UserGroup", "UserGroup.role"}, |
|
61
|
|
|
* ), |
|
62
|
|
|
* ), |
|
63
|
|
|
* ) |
|
64
|
|
|
* @OA\Response( |
|
65
|
|
|
* response=401, |
|
66
|
|
|
* description="Invalid token", |
|
67
|
|
|
* @OA\Schema( |
|
68
|
|
|
* example={ |
|
69
|
|
|
* "Token not found": "{code: 401, message: 'JWT Token not found'}", |
|
70
|
|
|
* "Expired token": "{code: 401, message: 'Expired JWT Token'}", |
|
71
|
|
|
* }, |
|
72
|
|
|
* ), |
|
73
|
|
|
* ) |
|
74
|
|
|
* @OA\Response( |
|
75
|
|
|
* response=404, |
|
76
|
|
|
* description="User Group not found", |
|
77
|
|
|
* ) |
|
78
|
|
|
* |
|
79
|
|
|
* @throws Throwable |
|
80
|
|
|
*/ |
|
81
|
5 |
|
#[Route( |
|
82
|
|
|
path: '/v1/user_group/{userGroup}/users', |
|
83
|
|
|
requirements: [ |
|
84
|
|
|
'userGroup' => '%app.uuid_v1_regex%', |
|
85
|
|
|
], |
|
86
|
|
|
methods: [Request::METHOD_GET], |
|
87
|
|
|
)] |
|
88
|
|
|
#[IsGranted(RolesService::ROLE_ADMIN)] |
|
89
|
|
|
#[ParamConverter( |
|
90
|
|
|
data: 'userGroup', |
|
91
|
|
|
class: UserGroupResource::class, |
|
92
|
|
|
)] |
|
93
|
|
|
public function __invoke(Request $request, UserGroup $userGroup): Response |
|
94
|
|
|
{ |
|
95
|
5 |
|
return $this->responseHandler |
|
96
|
5 |
|
->createResponse($request, $this->userResource->getUsersForGroup($userGroup), $this->userResource); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|