From 22fe8f189d1f42f990aad7d51e4fadf153f7ffed Mon Sep 17 00:00:00 2001 From: Ruslan Baidan Date: Wed, 20 Nov 2024 20:01:47 +0100 Subject: [PATCH] Added microseconds to the generation json file name of the clients' operations. --- src/Controller/ApiClientsController.php | 4 +--- src/Service/ClientService.php | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Controller/ApiClientsController.php b/src/Controller/ApiClientsController.php index a277c84..48266eb 100644 --- a/src/Controller/ApiClientsController.php +++ b/src/Controller/ApiClientsController.php @@ -82,9 +82,7 @@ public function delete($id) public function deleteList($data) { - foreach ($data as $id) { - $this->clientService->delete((int)$id); - } + $this->clientService->deleteList($data); return $this->getSuccessfulJsonResponse(); } diff --git a/src/Service/ClientService.php b/src/Service/ClientService.php index 40fdd07..ec4cf01 100644 --- a/src/Service/ClientService.php +++ b/src/Service/ClientService.php @@ -123,7 +123,7 @@ public function create(array $data): Client $this->clientTable->save($client); - $this->createJson($client); + $this->generateCreationJson($client); return $client; } @@ -219,7 +219,15 @@ public function delete($id): void $this->clientTable->remove($client); - $this->deleteJson($client); + $this->generateDeleteJson($client); + } + + public function deleteList(array $data): void + { + foreach ($this->clientTable->findByIds($data) as $client) { + $this->clientTable->remove($client); + + } } public function unlinkModel(int $modelId): void @@ -237,7 +245,7 @@ public function unlinkModel(int $modelId): void * * @throws JsonException|Exception */ - private function createJson(Client $client): void + private function generateCreationJson(Client $client): void { if (!isset($this->config['spool_path_create'])) { throw new Exception('The config option "spool_path_create" is required to generate clients creation.', 412); @@ -326,7 +334,7 @@ private function createJson(Client $client): void * * @throws JsonException|Exception */ - private function deleteJson(Client $client): void + private function generateDeleteJson(Client $client): void { if (!isset($this->config['spool_path_delete'])) { throw new Exception('The config option "spool_path_delete" is required to generate clients deletion.', 412); @@ -376,7 +384,7 @@ private function createJsonFileWithDataContent($path, array $data): void ); } - $filename = $path . date('YmdHis') . '.json'; + $filename = $path . date('YmdHisu') . '.json'; file_put_contents($filename, json_encode($data, JSON_THROW_ON_ERROR)); }