security->isGranted(EntityWorkflowVoter::SEE, $entityWorkflow)) { throw new AccessDeniedHttpException(); } $dto = new AddAttachmentRequestDTO($entityWorkflow); $this->serializer->deserialize($request->getContent(), AddAttachmentRequestDTO::class, 'json', [ AbstractNormalizer::OBJECT_TO_POPULATE => $dto, AbstractNormalizer::GROUPS => ['write'], ]); $errors = $this->validator->validate($dto); if (count($errors) > 0) { return new JsonResponse( $this->serializer->serialize($errors, 'json'), Response::HTTP_UNPROCESSABLE_ENTITY, json: true ); } $attachment = ($this->addAttachmentAction)($dto); $this->entityManager->flush(); return new JsonResponse( $this->serializer->serialize($attachment, 'json', [AbstractNormalizer::GROUPS => ['read']]), json: true ); } #[Route('/api/1.0/main/workflow/attachment/{id}', methods: ['DELETE'])] public function removeAttachment(EntityWorkflowAttachment $attachment): Response { if (!$this->security->isGranted(EntityWorkflowVoter::SEE, $attachment->getEntityWorkflow())) { throw new AccessDeniedHttpException(); } $this->entityManager->remove($attachment); $this->entityManager->flush(); return new Response(null, Response::HTTP_NO_CONTENT); } #[Route('/api/1.0/main/workflow/{id}/attachment', methods: ['GET'])] public function listAttachmentsForEntityWorkflow(EntityWorkflow $entityWorkflow): JsonResponse { if (!$this->security->isGranted(EntityWorkflowVoter::SEE, $entityWorkflow)) { throw new AccessDeniedHttpException(); } return new JsonResponse( $this->serializer->serialize( $entityWorkflow->getAttachments(), 'json', [AbstractNormalizer::GROUPS => ['read']] ), json: true ); } }