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);