<?php
declare(strict_types=1);
namespace App\Controller\V1\User;
use App\Entity\Netural\Watchlist;
use App\Entity\Vista\LoyaltyMember;
use App\Helper\WatchlistHelperInterface;
use FOS\RestBundle\Controller\Annotations\View;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security as NelmioSecurity;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Swagger\Annotations as SWG;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use App\Security\Security;
/**
* @Route("/users")
* @SWG\Tag(name="User_v1")
*/
class WatchlistController
{
/** @var WatchlistHelperInterface */
protected $watchlistHelperI;
/**
* WatchlistController constructor.
*
* @param WatchlistHelperInterface $watchlistHelperI
*/
public function __construct(WatchlistHelperInterface $watchlistHelperI)
{
$this->watchlistHelperI = $watchlistHelperI;
}
/**
* @Route("/watchlist/movie/{movieId}", methods={"POST"})
* @NelmioSecurity(name="Bearer")
* @View(statusCode=201, serializerGroups={"Default", "watchlist_details"})
*
* @SWG\Response(
* response="201",
* description="Entity successfully created",
* @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
*
* @param $movieId
* @param Security $security
* @return mixed
*/
public function watchlistMovieAction($movieId, Security $security)
{
if (!($user = $security->getUser()) instanceof LoyaltyMember) {
throw new AccessDeniedException();
}
return $this->watchlistHelperI->addMovie($user, $movieId);
}
/**
* @Route("/watchlist/event/{eventId}", methods={"POST"})
* @NelmioSecurity(name="Bearer")
* @View(statusCode=201, serializerGroups={"Default", "watchlist_details"})
*
* @SWG\Response(
* response="201",
* description="Entity successfully created",
* @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
*
* @param $eventId
* @param Security $security
* @return Watchlist
*/
public function watchlistEventAction($eventId, Security $security)
{
if (!($user = $security->getUser()) instanceof LoyaltyMember) {
throw new AccessDeniedException();
}
return $this->watchlistHelperI->addEvent($user, $eventId);
}
/**
* @Route("/watchlist", methods={"DELETE"})
* @ParamConverter("items", converter="fos_rest.request_body", class="array<App\Entity\Netural\WatchlistEntry>")
* @NelmioSecurity(name="Bearer")
* @View(statusCode=202)
*
* @SWG\Parameter(
* name="body",
* in="body",
* @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
* @SWG\Response(
* response="202",
* description="Movie successfully removed")
*
* @param array $items
* @param Security $security
* @return mixed
*/
public function deleteAction(array $items, Security $security)
{
if (!($user = $security->getUser()) instanceof LoyaltyMember) {
throw new AccessDeniedException();
}
return $this->watchlistHelperI->deleteEntries($user, $items);
}
/**
* @Route("/watchlist/movie", methods={"DELETE"})
* @ParamConverter("items", converter="fos_rest.request_body", class="array<string>")
* @NelmioSecurity(name="Bearer")
* @View(statusCode=202)
*
* @SWG\Parameter(
* name="body",
* in="body",
* @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
* @SWG\Response(
* response="202",
* description="Movie successfully removed")
*
* @param array $items
* @param Security $security
* @return mixed
*/
public function deleteMoviesAction(array $items, Security $security)
{
if (!($user = $security->getUser()) instanceof LoyaltyMember) {
throw new AccessDeniedException();
}
return $this->watchlistHelperI->deleteMovies($user, $items);
}
/**
* @Route("/watchlist/event", methods={"DELETE"})
* @ParamConverter("items", converter="fos_rest.request_body", class="array<string>")
* @NelmioSecurity(name="Bearer")
* @View(statusCode=202)
*
* @SWG\Parameter(
* name="body",
* in="body",
* @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
* @SWG\Response(
* response="202",
* description="Movie successfully removed")
*
* @param array $items
* @param Security $security
* @return mixed
*/
public function deleteEventsAction(array $items, Security $security)
{
if (!($user = $security->getUser()) instanceof LoyaltyMember) {
throw new AccessDeniedException();
}
return $this->watchlistHelperI->deleteEvents($user, $items);
}
/**
* @Route("/watchlist", methods={"GET"})
* @NelmioSecurity(name="Bearer")
* @View(serializerGroups={"Default", "watchlist_details"})
*
* @SWG\Response(
* response="200",
* description="Watchlist",
* @SWG\Schema(@Model(type=\App\Entity\Netural\Watchlist::class)))
*
* @param Security $security
* @return Watchlist
*/
public function watchlistAction(Security $security)
{
if (!($user = $security->getUser()) instanceof LoyaltyMember) {
throw new AccessDeniedException();
}
return $this->watchlistHelperI->getAll($user);
}
}