From 1afe73bd0937f4a002bca5b9fb334a9f1f45445c Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 16 Sep 2024 13:55:57 +0200 Subject: [PATCH] refs #659. CommandGroup. Added 'add-command' endpoint --- config/api_platform/CommandGroup.yaml | 7 ++++ .../CommandGroupAddCommandsAction.php | 35 +++++++++++++++++++ .../Input/CommandGroupAddCommandsInput.php | 17 +++++++++ src/State/Provider/CommandGroupProvider.php | 2 +- 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/Controller/CommandGroupAddCommandsAction.php create mode 100644 src/Dto/Input/CommandGroupAddCommandsInput.php diff --git a/config/api_platform/CommandGroup.yaml b/config/api_platform/CommandGroup.yaml index 6e0cda9..40ede0b 100644 --- a/config/api_platform/CommandGroup.yaml +++ b/config/api_platform/CommandGroup.yaml @@ -24,6 +24,13 @@ resources: ApiPlatform\Metadata\Post: ~ ApiPlatform\Metadata\Delete: ~ + add_commands: + class: ApiPlatform\Metadata\Post + method: POST + input: App\Dto\Input\CommandGroupAddCommandsInput + uriTemplate: /command-groups/{uuid}/add-commands + controller: App\Controller\CommandGroupAddCommandsAction + properties: App\Entity\CommandGroup: id: diff --git a/src/Controller/CommandGroupAddCommandsAction.php b/src/Controller/CommandGroupAddCommandsAction.php new file mode 100644 index 0000000..e779057 --- /dev/null +++ b/src/Controller/CommandGroupAddCommandsAction.php @@ -0,0 +1,35 @@ +commands; + + /** @var Command $command */ + foreach ($commands as $command) { + $commandGroup->addCommand($command->getEntity()); + } + + $this->entityManager->persist($commandGroup); + $this->entityManager->flush(); + + return new JsonResponse(data: 'Commands added to command group successfully', status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Dto/Input/CommandGroupAddCommandsInput.php b/src/Dto/Input/CommandGroupAddCommandsInput.php new file mode 100644 index 0000000..2b14a7b --- /dev/null +++ b/src/Dto/Input/CommandGroupAddCommandsInput.php @@ -0,0 +1,17 @@ +collectionProvider->provide($operation, $uriVariables, $context);