From 0c94a1921e01173e20ed947e1acc745ba7b3d3ca Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 22 Oct 2024 22:20:21 +0200 Subject: [PATCH] refs #952. First revision status endpoint ogAgent --- src/Controller/OgAgent/StatusAction.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Controller/OgAgent/StatusAction.php b/src/Controller/OgAgent/StatusAction.php index 3b58617..76864f0 100644 --- a/src/Controller/OgAgent/StatusAction.php +++ b/src/Controller/OgAgent/StatusAction.php @@ -45,27 +45,23 @@ class StatusAction extends AbstractController } try { - $response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/ogAdmClient/status'); + $response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status'); - if ($response->getStatusCode() !== Response::HTTP_OK) { - $client->setStatus('off'); - $this->entityManager->persist($client); - $this->entityManager->flush(); - } else if ($response->getStatusCode() === Response::HTTP_OK) { - $client->setStatus('active'); - $this->entityManager->persist($client); - $this->entityManager->flush(); - } + $statusCode = $response->getStatusCode(); + $client->setStatus($statusCode === Response::HTTP_OK ? 'active' : 'off'); } catch (TransportExceptionInterface $e) { - $client->setStatus('off'); - $this->entityManager->persist($client); - $this->entityManager->flush(); - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); + return new JsonResponse( + data: ['error' => 'An error occurred while communicating with the client'], + status: Response::HTTP_INTERNAL_SERVER_ERROR + ); } + $this->entityManager->persist($client); + $this->entityManager->flush(); + return new JsonResponse(status: Response::HTTP_OK); } } \ No newline at end of file