Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @Route("", name="", methods={"POST"})
- * @Permissions(adminPermissions=true)
- *
- * @param Task $task
- * @param Request $request
- * @param Publish\Handler $handler
- * @return JsonResponse
- * @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
- */
- public function publish(Task $task, Request $request, Publish\Handler $handler): JsonResponse
- {
- /** @var Publish\Command $command */
- $command = $this->denormalizer->denormalize(
- $request->request->all(),
- Publish\Command::class,
- 'array',
- [
- 'ignored_attributes' => ['user', 'task']
- ]
- );
- $command->user = $this->getUser();
- $command->task = $task;
- $violations = $this->validator->validate($command);
- $errors = [];
- if (\count($violations) > 0) {
- /** @var ConstraintViolation $violation */
- foreach ($violations as $violation) {
- $errors[] = $violation->getMessage();
- }
- return $this->json(['error' => $errors], 200);
- }
- try {
- $handler->handle($command);
- return $this->json(['success' => 1], 200);
- } catch (\DomainException $e) {
- $this->logger->warning($e->getMessage());
- return $this->json(['success' => 0], 500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement