Skip to content

Commit

Permalink
Added microseconds to the generation json file name of the clients' o…
Browse files Browse the repository at this point in the history
…perations.
  • Loading branch information
ruslanbaidan committed Nov 20, 2024
1 parent ff1ddc3 commit 22fe8f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/Controller/ApiClientsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
18 changes: 13 additions & 5 deletions src/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function create(array $data): Client

$this->clientTable->save($client);

$this->createJson($client);
$this->generateCreationJson($client);

return $client;
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 22fe8f1

Please sign in to comment.