src/Controller/V1/User/WatchlistController.php line 177

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\V1\User;
  4. use App\Entity\Netural\Watchlist;
  5. use App\Entity\Vista\LoyaltyMember;
  6. use App\Helper\WatchlistHelperInterface;
  7. use FOS\RestBundle\Controller\Annotations\View;
  8. use Nelmio\ApiDocBundle\Annotation\Model;
  9. use Nelmio\ApiDocBundle\Annotation\Security as NelmioSecurity;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  11. use Swagger\Annotations as SWG;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  14. use App\Security\Security;
  15. /**
  16.  * @Route("/users")
  17.  * @SWG\Tag(name="User_v1")
  18.  */
  19. class WatchlistController
  20. {
  21.     /** @var WatchlistHelperInterface */
  22.     protected $watchlistHelperI;
  23.     /**
  24.      * WatchlistController constructor.
  25.      *
  26.      * @param WatchlistHelperInterface $watchlistHelperI
  27.      */
  28.     public function __construct(WatchlistHelperInterface $watchlistHelperI)
  29.     {
  30.         $this->watchlistHelperI $watchlistHelperI;
  31.     }
  32.     /**
  33.      * @Route("/watchlist/movie/{movieId}", methods={"POST"})
  34.      * @NelmioSecurity(name="Bearer")
  35.      * @View(statusCode=201, serializerGroups={"Default", "watchlist_details"})
  36.      *
  37.      * @SWG\Response(
  38.      *     response="201",
  39.      *     description="Entity successfully created",
  40.      *     @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
  41.      *
  42.      * @param $movieId
  43.      * @param Security $security
  44.      * @return mixed
  45.      */
  46.     public function watchlistMovieAction($movieIdSecurity $security)
  47.     {
  48.         if (!($user $security->getUser()) instanceof LoyaltyMember) {
  49.             throw new AccessDeniedException();
  50.         }
  51.         return $this->watchlistHelperI->addMovie($user$movieId);
  52.     }
  53.     /**
  54.      * @Route("/watchlist/event/{eventId}", methods={"POST"})
  55.      * @NelmioSecurity(name="Bearer")
  56.      * @View(statusCode=201, serializerGroups={"Default", "watchlist_details"})
  57.      *
  58.      * @SWG\Response(
  59.      *     response="201",
  60.      *     description="Entity successfully created",
  61.      *     @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
  62.      *
  63.      * @param $eventId
  64.      * @param Security $security
  65.      * @return Watchlist
  66.      */
  67.     public function watchlistEventAction($eventIdSecurity $security)
  68.     {
  69.         if (!($user $security->getUser()) instanceof LoyaltyMember) {
  70.             throw new AccessDeniedException();
  71.         }
  72.         return $this->watchlistHelperI->addEvent($user$eventId);
  73.     }
  74.     /**
  75.      * @Route("/watchlist", methods={"DELETE"})
  76.      * @ParamConverter("items", converter="fos_rest.request_body", class="array<App\Entity\Netural\WatchlistEntry>")
  77.      * @NelmioSecurity(name="Bearer")
  78.      * @View(statusCode=202)
  79.      *
  80.      * @SWG\Parameter(
  81.      *     name="body",
  82.      *     in="body",
  83.      *     @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
  84.      * @SWG\Response(
  85.      *     response="202",
  86.      *     description="Movie successfully removed")
  87.      *
  88.      * @param array $items
  89.      * @param Security $security
  90.      * @return mixed
  91.      */
  92.     public function deleteAction(array $itemsSecurity $security)
  93.     {
  94.         if (!($user $security->getUser()) instanceof LoyaltyMember) {
  95.             throw new AccessDeniedException();
  96.         }
  97.         return $this->watchlistHelperI->deleteEntries($user$items);
  98.     }
  99.     /**
  100.      * @Route("/watchlist/movie", methods={"DELETE"})
  101.      * @ParamConverter("items", converter="fos_rest.request_body", class="array<string>")
  102.      * @NelmioSecurity(name="Bearer")
  103.      * @View(statusCode=202)
  104.      *
  105.      * @SWG\Parameter(
  106.      *     name="body",
  107.      *     in="body",
  108.      *     @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
  109.      * @SWG\Response(
  110.      *     response="202",
  111.      *     description="Movie successfully removed")
  112.      *
  113.      * @param array $items
  114.      * @param Security $security
  115.      * @return mixed
  116.      */
  117.     public function deleteMoviesAction(array $itemsSecurity $security)
  118.     {
  119.         if (!($user $security->getUser()) instanceof LoyaltyMember) {
  120.             throw new AccessDeniedException();
  121.         }
  122.         return $this->watchlistHelperI->deleteMovies($user$items);
  123.     }
  124.     /**
  125.      * @Route("/watchlist/event", methods={"DELETE"})
  126.      * @ParamConverter("items", converter="fos_rest.request_body", class="array<string>")
  127.      * @NelmioSecurity(name="Bearer")
  128.      * @View(statusCode=202)
  129.      *
  130.      * @SWG\Parameter(
  131.      *     name="body",
  132.      *     in="body",
  133.      *     @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
  134.      * @SWG\Response(
  135.      *     response="202",
  136.      *     description="Movie successfully removed")
  137.      *
  138.      * @param array $items
  139.      * @param Security $security
  140.      * @return mixed
  141.      */
  142.     public function deleteEventsAction(array $itemsSecurity $security)
  143.     {
  144.         if (!($user $security->getUser()) instanceof LoyaltyMember) {
  145.             throw new AccessDeniedException();
  146.         }
  147.         return $this->watchlistHelperI->deleteEvents($user$items);
  148.     }
  149.     /**
  150.      * @Route("/watchlist", methods={"GET"})
  151.      * @NelmioSecurity(name="Bearer")
  152.      * @View(serializerGroups={"Default", "watchlist_details"})
  153.      *
  154.      * @SWG\Response(
  155.      *     response="200",
  156.      *     description="Watchlist",
  157.      *     @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
  158.      *
  159.      * @param Security $security
  160.      * @return Watchlist
  161.      */
  162.     public function watchlistAction(Security $security)
  163.     {
  164.         if (!($user $security->getUser()) instanceof LoyaltyMember) {
  165.             throw new AccessDeniedException();
  166.         }
  167.         return $this->watchlistHelperI->getAll($user);
  168.     }
  169. }