66
77use App \Entity \ScreenUser ;
88use App \Entity \Tenant \Slide ;
9- use App \Entity \User ;
10- use App \Exceptions \InteractiveSlideException ;
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 ;
16- use Symfony \Component \HttpKernel \Exception \HttpException ;
17- use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
18+ use Symfony \Component \HttpKernel \Exception \AccessDeniedHttpException ;
1819
1920#[AsController]
2021final readonly class InteractiveController
@@ -24,27 +25,27 @@ public function __construct(
2425 private Security $ security ,
2526 ) {}
2627
28+ /**
29+ * @throws ConflictException
30+ * @throws BadRequestException
31+ * @throws NotAcceptableException
32+ * @throws TooManyRequestsException
33+ */
2734 public function __invoke (Request $ request , Slide $ slide ): JsonResponse
2835 {
29- $ requestBody = $ request -> toArray ();
36+ $ user = $ this -> security -> getUser ();
3037
31- try {
32- $ interactionRequest = $ this ->interactiveSlideService ->parseRequestBody ($ requestBody );
33- } catch (InteractiveSlideException $ e ) {
34- throw new HttpException ($ e ->getCode (), $ e ->getMessage ());
38+ if (!($ user instanceof ScreenUser)) {
39+ throw new AccessDeniedHttpException ('Only screen user can perform action. ' );
3540 }
3641
37- $ user = $ this -> security -> getUser ();
42+ $ tenant = $ user -> getActiveTenant ();
3843
39- if (!($ user instanceof User || $ user instanceof ScreenUser)) {
40- throw new NotFoundHttpException ('User not found ' );
41- }
44+ $ requestBody = $ request ->toArray ();
4245
43- try {
44- $ actionResult = $ this ->interactiveSlideService ->performAction ($ user , $ slide , $ interactionRequest );
45- } catch (InteractiveSlideException $ e ) {
46- throw new HttpException ($ e ->getCode (), $ e ->getMessage ());
47- }
46+ $ interactionRequest = $ this ->interactiveSlideService ->parseRequestBody ($ requestBody );
47+
48+ $ actionResult = $ this ->interactiveSlideService ->performAction ($ tenant , $ slide , $ interactionRequest );
4849
4950 return new JsonResponse ($ actionResult );
5051 }
0 commit comments