-
-
Notifications
You must be signed in to change notification settings - Fork 979
Closed
Labels
Description
Hi
I try to personalize the post in an action but it asks me an id?
namespace AppBundle\Action;
use AppBundle\Entity\Book;
use Doctrine\Common\Persistence\ManagerRegistry;
use GuzzleHttp\Psr7\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
class BookSpecial
{
private $myService;
/**
* @var Container
*/
private $container;
public function __construct(MyService $myService,Container $container, AuthorizationChecker $checker)
{
$this->myService = $myService;
$this->container = $container;
$this->authorizationChecker = $checker;
}
/**
* @Route(
* name="book_special",
* path="api/books/special",
* defaults={"_api_resource_class"=Book::class, "_api_item_operation_name"="special"},
* options={"i18n" = false }
* )
* @Method("POST")
*/
public function __invoke($data)
{
if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
$data = array('error'=>410);
return new JsonResponse($data, 400);
}
$this->myService->doSomething($data);
return $data; // API Platform will automatically validate, persist (if you use Doctrine) and serialize an entity
// for you. If you prefer to do it yourself, return an instance of Symfony\Component\HttpFoundation\Response
}
}