6
6
7
7
use App \Entity \ScreenUser ;
8
8
use App \Entity \Tenant \Slide ;
9
- use App \Entity \User ;
10
- use App \Exceptions \NotFoundException ;
9
+ use App \Exceptions \BadRequestException ;
10
+ use App \Exceptions \ConflictException ;
11
+ use App \Exceptions \NotAcceptableException ;
12
+ use App \Exceptions \TooManyRequestsException ;
11
13
use App \Service \InteractiveSlideService ;
12
14
use Symfony \Bundle \SecurityBundle \Security ;
13
15
use Symfony \Component \HttpFoundation \JsonResponse ;
14
16
use Symfony \Component \HttpFoundation \Request ;
15
17
use Symfony \Component \HttpKernel \Attribute \AsController ;
18
+ use Symfony \Component \HttpKernel \Exception \AccessDeniedHttpException ;
16
19
17
20
#[AsController]
18
21
final readonly class InteractiveController
@@ -22,18 +25,28 @@ public function __construct(
22
25
private Security $ security ,
23
26
) {}
24
27
28
+ /**
29
+ * @throws ConflictException
30
+ * @throws BadRequestException
31
+ * @throws NotAcceptableException
32
+ * @throws TooManyRequestsException
33
+ */
25
34
public function __invoke (Request $ request , Slide $ slide ): JsonResponse
26
35
{
36
+ $ user = $ this ->security ->getUser ();
37
+
38
+ if (!($ user instanceof ScreenUser)) {
39
+ throw new AccessDeniedHttpException ('Only screen user can perform action. ' );
40
+ }
41
+
42
+ $ tenant = $ user ->getActiveTenant ();
43
+
27
44
$ requestBody = $ request ->toArray ();
28
45
29
46
$ interactionRequest = $ this ->interactiveSlideService ->parseRequestBody ($ requestBody );
30
47
31
- $ user = $ this ->security ->getUser ();
32
-
33
- if (!($ user instanceof User || $ user instanceof ScreenUser)) {
34
- throw new NotFoundException ('User not found ' );
35
- }
48
+ $ actionResult = $ this ->interactiveSlideService ->performAction ($ tenant , $ slide , $ interactionRequest );
36
49
37
- return new JsonResponse ($ this -> interactiveSlideService -> performAction ( $ user , $ slide , $ interactionRequest ) );
50
+ return new JsonResponse ($ actionResult );
38
51
}
39
52
}
0 commit comments