src/Controller/LivecamController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Security\ApiUser;
  4. use App\Service\Client\LivecamService;
  5. use App\Service\Client\User\AmateurListingService;
  6. use App\Service\Client\User\MemberPropertyService;
  7. use App\Service\Client\User\MemberService;
  8. use App\Service\LivecamOnlineService;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. /**
  15.  * @Route("/livecams")
  16.  */
  17. class LivecamController extends AbstractController
  18. {
  19.     public function __construct(
  20.         protected LivecamService        $livecamService,
  21.         protected MemberService         $memberService,
  22.         protected AmateurListingService $amateurService,
  23.         protected MemberPropertyService $propertyService
  24.     )
  25.     {
  26.     }
  27.     /**
  28.      * @Route("/{page}", requirements={"page": "\d+"}, defaults={"page": 1})
  29.      * @Template()
  30.      * @param int $page
  31.      * @param LivecamOnlineService $livecamOnlineService
  32.      * @return array
  33.      */
  34.     public function index(int $pageLivecamOnlineService $livecamOnlineService): array
  35.     {
  36.         $livecamAmateurs $this->amateurService->getLivecamAmateurs($page15$livecamOnlineService);
  37.         $onlineAmateurs $this->amateurService->getOnlineAmateurs(115);
  38.         return [
  39.             'amateurs' => $livecamAmateurs,
  40.             'online_amateurs' => $onlineAmateurs,
  41.             'page' => $page
  42.         ];
  43.     }
  44.     /**
  45.      * @Route("/app/watch/{username}")
  46.      * @Template()
  47.      * @param string $username
  48.      * @return array|RedirectResponse
  49.      * @throws \Psr\Cache\InvalidArgumentException
  50.      * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
  51.      * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
  52.      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
  53.      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
  54.      */
  55.     public function watch(string $username)
  56.     {
  57.         $this->denyAccessUnlessGranted('ROLE_MEMBER');
  58.         try {
  59.             $amateur $this->memberService->getMemberDetailByUsername($username);
  60.         } catch (NotFoundHttpException $e) {
  61.             if (empty($amateur) || !$amateur['is_amateur'] || !$amateur['is_active']) {
  62.                 throw $this->createNotFoundException('Amateur nicht gefunden.');
  63.             }
  64.         }
  65.         /**
  66.          * @var $user ApiUser
  67.          */
  68.         $user $this->getUser();
  69.         return [
  70.             'isDev' => $this->getParameter('kernel.environment') === "dev",
  71.             'amateur' => $amateur,
  72.             'appConfig' => [
  73.                 'amateurName' => $amateur['username'],
  74.                 'memberName' => $user $this->getUser()->getUserIdentifier(),
  75.                 'socketUrl' => $this->livecamService->getSocketUrl(),
  76.             ]
  77.         ];
  78.     }
  79.     /**
  80.      * @Route("/app/send")
  81.      * @Template()
  82.      * @return array
  83.      */
  84.     public function send(): array
  85.     {
  86.         $this->denyAccessUnlessGranted('ROLE_AMATEUR');
  87.         return [
  88.             'isDev' => $this->getParameter('kernel.environment') === "dev",
  89.             'appConfig' => [
  90.                 'amateurName' => $user $this->getUser()->getUserIdentifier(),
  91.                 'socketUrl' => $this->livecamService->getSocketUrl(),
  92.             ]
  93.         ];
  94.     }
  95. }