66
77use App \Entity \ScreenUser ;
88use 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 ;
1113use App \Service \InteractiveSlideService ;
1214use Symfony \Bundle \SecurityBundle \Security ;
1315use Symfony \Component \HttpFoundation \JsonResponse ;
1416use Symfony \Component \HttpFoundation \Request ;
1517use Symfony \Component \HttpKernel \Attribute \AsController ;
18+ use Symfony \Component \HttpKernel \Exception \AccessDeniedHttpException ;
1619
1720#[AsController]
1821final readonly class InteractiveController
@@ -22,18 +25,28 @@ public function __construct(
2225 private Security $ security ,
2326 ) {}
2427
28+ /**
29+ * @throws ConflictException
30+ * @throws BadRequestException
31+ * @throws NotAcceptableException
32+ * @throws TooManyRequestsException
33+ */
2534 public function __invoke (Request $ request , Slide $ slide ): JsonResponse
2635 {
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+
2744 $ requestBody = $ request ->toArray ();
2845
2946 $ interactionRequest = $ this ->interactiveSlideService ->parseRequestBody ($ requestBody );
3047
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 );
3649
37- return new JsonResponse ($ this -> interactiveSlideService -> performAction ( $ user , $ slide , $ interactionRequest ) );
50+ return new JsonResponse ($ actionResult );
3851 }
3952}
0 commit comments