From 34c2144ffd973bbdab395e58a382d78df57809eb Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 24 Sep 2024 09:09:29 +0200 Subject: [PATCH] refs #659. CommandGroup execute endpoint --- README.md | 2 - config/api_platform/Command.yaml | 2 +- config/api_platform/CommandGroup.yaml | 7 +++ config/packages/api_platform.yaml | 4 +- src/Controller/CommandGroupExecuteAction.php | 46 ++++++++++++++++++++ src/Dto/Input/CommandGroupExecuteInput.php | 17 ++++++++ src/Entity/Command.php | 2 +- 7 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/Controller/CommandGroupExecuteAction.php create mode 100644 src/Dto/Input/CommandGroupExecuteInput.php diff --git a/README.md b/README.md index 54d5c90..ad2d3fa 100644 --- a/README.md +++ b/README.md @@ -134,8 +134,6 @@ docker exec ogcore-php php bin/console opengnsys:migration:hardware-profiles #ca docker exec ogcore-php php bin/console opengnsys:migration:clients #cargamos los clientes docker exec ogcore-php php bin/console opengnsys:migration:os #cargamos los sistemas operativos docker exec ogcore-php php bin/console opengnsys:migration:partition #cargamos las particiones - - ``` ## Objetos de interés diff --git a/config/api_platform/Command.yaml b/config/api_platform/Command.yaml index fa14e2b..425259b 100644 --- a/config/api_platform/Command.yaml +++ b/config/api_platform/Command.yaml @@ -24,7 +24,7 @@ resources: ApiPlatform\Metadata\Post: ~ ApiPlatform\Metadata\Delete: ~ - execute: + command_execute: class: ApiPlatform\Metadata\Post method: POST input: App\Dto\Input\CommandExecuteInput diff --git a/config/api_platform/CommandGroup.yaml b/config/api_platform/CommandGroup.yaml index 40ede0b..aa09ccc 100644 --- a/config/api_platform/CommandGroup.yaml +++ b/config/api_platform/CommandGroup.yaml @@ -31,6 +31,13 @@ resources: uriTemplate: /command-groups/{uuid}/add-commands controller: App\Controller\CommandGroupAddCommandsAction + command_group_execute: + class: ApiPlatform\Metadata\Post + method: POST + input: App\Dto\Input\CommandGroupExecuteInput + uriTemplate: /command-groups/{uuid}/execute + controller: App\Controller\CommandGroupExecuteAction + properties: App\Entity\CommandGroup: id: diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index 352abc2..ee6fc53 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -40,4 +40,6 @@ api_platform: api_keys: apiKey: name: Authorization - type: header \ No newline at end of file + type: header + exception_to_status: + Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException: 409 \ No newline at end of file diff --git a/src/Controller/CommandGroupExecuteAction.php b/src/Controller/CommandGroupExecuteAction.php new file mode 100644 index 0000000..563a488 --- /dev/null +++ b/src/Controller/CommandGroupExecuteAction.php @@ -0,0 +1,46 @@ +clients; + + foreach ($commandGroup->getCommands() as $command) { + /** @var Client $client */ + foreach ($clients as $client) { + $trace = new Trace(); + $trace->setClient($client->getEntity()); + $trace->setCommand($command); + $trace->setStatus(TraceStatus::IN_PROGRESS); + $trace->setExecutedAt(new \DateTimeImmutable()); + + $this->entityManager->persist($trace); + } + } + + $this->entityManager->flush(); + + return new JsonResponse(data: 'Command group executed successfully', status: Response::HTTP_OK); + } +} \ No newline at end of file diff --git a/src/Dto/Input/CommandGroupExecuteInput.php b/src/Dto/Input/CommandGroupExecuteInput.php new file mode 100644 index 0000000..19dd317 --- /dev/null +++ b/src/Dto/Input/CommandGroupExecuteInput.php @@ -0,0 +1,17 @@ + */ - #[ORM\ManyToMany(targetEntity: CommandTask::class, mappedBy: 'command')] + #[ORM\ManyToMany(targetEntity: CommandTask::class, mappedBy: 'commands')] private Collection $commandTasks; public function __construct()