diff --git a/config/api_platform/OgLive.yaml b/config/api_platform/OgLive.yaml index d69ddad..e24c61b 100644 --- a/config/api_platform/OgLive.yaml +++ b/config/api_platform/OgLive.yaml @@ -90,7 +90,6 @@ resources: class: ApiPlatform\Metadata\Post method: POST input: false - output: false uriTemplate: /og-lives/server/{uuid}/uninstall controller: App\Controller\OgBoot\OgLive\UninstallAction diff --git a/src/Controller/OgBoot/AbstractOgBootController.php b/src/Controller/OgBoot/AbstractOgBootController.php new file mode 100644 index 0000000..7e96b1c --- /dev/null +++ b/src/Controller/OgBoot/AbstractOgBootController.php @@ -0,0 +1,56 @@ + [ + 'accept' => 'application/json', + 'Content-Type' => 'application/json' + ], + ]); + + try { + $response = $httpClient->request($method, $url, $params); + + return json_decode($response->getContent(), true); + } catch (ClientExceptionInterface | ServerExceptionInterface $e) { + $response = $e->getResponse(); + $content = json_decode($response->getContent(false), true); + throw new HttpException($response->getStatusCode(), $content['error'] ?? 'An error occurred'); + } catch (TransportExceptionInterface $e) { + throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, $e->getMessage()); + } + } +} diff --git a/src/Controller/OgBoot/AbstractOgLiveController.php b/src/Controller/OgBoot/AbstractOgLiveController.php deleted file mode 100644 index 89cbb0c..0000000 --- a/src/Controller/OgBoot/AbstractOgLiveController.php +++ /dev/null @@ -1,20 +0,0 @@ -request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum(), [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); + if (!$data->getChecksum()) { + throw new ValidatorException('Checksum is required'); } - $data = json_decode($response->getContent(), true); + $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse(data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/GetCollectionAction.php b/src/Controller/OgBoot/OgLive/GetCollectionAction.php index 236a7fc..930b237 100644 --- a/src/Controller/OgBoot/OgLive/GetCollectionAction.php +++ b/src/Controller/OgBoot/OgLive/GetCollectionAction.php @@ -2,10 +2,11 @@ namespace App\Controller\OgBoot\OgLive; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; @@ -13,7 +14,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class GetCollectionAction extends AbstractOgLiveController +class GetCollectionAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -23,18 +24,8 @@ class GetCollectionAction extends AbstractOgLiveController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives', [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); - } + $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives'); - $data = json_decode($response->getContent(), true); - - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse(data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/GetDefaultAction.php b/src/Controller/OgBoot/OgLive/GetDefaultAction.php index 9d0ff93..94f3456 100644 --- a/src/Controller/OgBoot/OgLive/GetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/GetDefaultAction.php @@ -2,7 +2,7 @@ namespace App\Controller\OgBoot\OgLive; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; @@ -13,7 +13,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class GetDefaultAction extends AbstractOgLiveController +class GetDefaultAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -23,18 +23,8 @@ class GetDefaultAction extends AbstractOgLiveController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); - } + $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/default'); - $data = json_decode($response->getContent(), true); - - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse(status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/GetIsosAction.php b/src/Controller/OgBoot/OgLive/GetIsosAction.php index 2ad93b4..90ddb19 100644 --- a/src/Controller/OgBoot/OgLive/GetIsosAction.php +++ b/src/Controller/OgBoot/OgLive/GetIsosAction.php @@ -2,7 +2,7 @@ namespace App\Controller\OgBoot\OgLive; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\OgLive; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -14,7 +14,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class GetIsosAction extends AbstractOgLiveController +class GetIsosAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -24,20 +24,8 @@ class GetIsosAction extends AbstractOgLiveController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - $ogLivesInserted = 0; + $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/isos'); - try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives/isos', [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); - } - - $data = json_decode($response->getContent(), true); - - return new JsonResponse( data: [ 'data' => $data, 'ogLivesInserted' => $ogLivesInserted], status: Response::HTTP_OK); + return new JsonResponse(data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/InstallAction.php b/src/Controller/OgBoot/OgLive/InstallAction.php index 7868240..e9b871c 100644 --- a/src/Controller/OgBoot/OgLive/InstallAction.php +++ b/src/Controller/OgBoot/OgLive/InstallAction.php @@ -2,12 +2,13 @@ namespace App\Controller\OgBoot\OgLive; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\OgLive; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; @@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class InstallAction extends AbstractOgLiveController +class InstallAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -25,28 +26,22 @@ class InstallAction extends AbstractOgLiveController */ public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - try { - $response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', [ - 'headers' => [ - 'accept' => 'application/json', - 'Content-Type' => 'application/json', - ], - 'json' => [ - 'url' => $data->getDownloadUrl() - ] - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: $e->getMessage(), status: Response::HTTP_INTERNAL_SERVER_ERROR); + if (!$data->getDownloadUrl()) { + throw new ValidatorException('Download URL is required'); } - if ($response->getStatusCode() === Response::HTTP_OK) { - $data->setInstalled(true); - $entityManager->persist($data); - $entityManager->flush(); - } + $params = [ + 'json' => [ + 'url' => $data->getDownloadUrl() + ] + ]; - $data = json_decode($response->getContent(), true); + $content = $this->createRequest($httpClient, 'POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', $params); - return new JsonResponse( data: $data, status: Response::HTTP_OK); + $data->setInstalled(true); + $entityManager->persist($data); + $entityManager->flush(); + + return new JsonResponse(data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/SetDefaultAction.php b/src/Controller/OgBoot/OgLive/SetDefaultAction.php index 3864e67..b0d9698 100644 --- a/src/Controller/OgBoot/OgLive/SetDefaultAction.php +++ b/src/Controller/OgBoot/OgLive/SetDefaultAction.php @@ -2,12 +2,13 @@ namespace App\Controller\OgBoot\OgLive; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\OgLive; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; @@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class SetDefaultAction extends AbstractOgLiveController +class SetDefaultAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -25,27 +26,22 @@ class SetDefaultAction extends AbstractOgLiveController */ public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - try { - $response = $httpClient->request('PUT', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', [ - 'headers' => [ - 'accept' => 'application/json', - ], - 'json' => [ - 'checksum' => $data->getChecksum() - ] - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); + if (!$data->getChecksum()) { + throw new ValidatorException('Checksum URL is required'); } - if ($response->getStatusCode() === Response::HTTP_OK) { - $data->setIsDefault(true); - $entityManager->persist($data); - $entityManager->flush(); - } + $params = [ + 'json' => [ + 'checksum' => $data->getChecksum() + ] + ]; - $data = json_decode($response->getContent(), true); + $content = $this->createRequest($httpClient, 'PUT', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', $params); - return new JsonResponse( data: $data, status: Response::HTTP_OK); + $data->setIsDefault(true); + $entityManager->persist($data); + $entityManager->flush(); + + return new JsonResponse(status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/SyncAction.php b/src/Controller/OgBoot/OgLive/SyncAction.php index 6171cc8..dfabadb 100644 --- a/src/Controller/OgBoot/OgLive/SyncAction.php +++ b/src/Controller/OgBoot/OgLive/SyncAction.php @@ -2,12 +2,13 @@ namespace App\Controller\OgBoot\OgLive; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\OgLive; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; @@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class SyncAction extends AbstractOgLiveController +class SyncAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -25,46 +26,37 @@ class SyncAction extends AbstractOgLiveController */ public function __invoke(HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/oglives', [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); + $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl . '/ogboot/v1/oglives'); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); - } - - $data = json_decode($response->getContent(), true); - - foreach ($data['installed_ogLives'] as $ogLive) { + foreach ($content['installed_ogLives'] as $ogLive) { $ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]); if ($ogLiveEntity) { - $ogLiveEntity->setName($ogLive['filename']); - $ogLiveEntity->setInstalled(true); - $ogLiveEntity->setArchitecture($ogLive['architecture']); - $ogLiveEntity->setKernel($ogLive['kernel']); - $ogLiveEntity->setRevision($ogLive['revision']); - $ogLiveEntity->setDirectory($ogLive['directory']); - $ogLiveEntity->setChecksum($ogLive['id']); + $this->extracted($ogLiveEntity, $ogLive); $this->entityManager->persist($ogLiveEntity); } else { $ogLiveEntity = new OgLive(); - $ogLiveEntity->setName($ogLive['filename']); - $ogLiveEntity->setInstalled(true); - $ogLiveEntity->setArchitecture($ogLive['architecture']); - $ogLiveEntity->setKernel($ogLive['kernel']); - $ogLiveEntity->setRevision($ogLive['revision']); - $ogLiveEntity->setDirectory($ogLive['directory']); - $ogLiveEntity->setChecksum($ogLive['id']); + $this->extracted($ogLiveEntity, $ogLive); } $this->entityManager->persist($ogLiveEntity); - } - $this->entityManager->flush(); - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse(data: $content, status: Response::HTTP_OK); + } + + /** + * @param OgLive|null $ogLiveEntity + * @param mixed $ogLive + * @return void + */ + public function extracted(OgLive|null $ogLiveEntity, mixed $ogLive): void + { + $ogLiveEntity->setName($ogLive['filename']); + $ogLiveEntity->setInstalled(true); + $ogLiveEntity->setArchitecture($ogLive['architecture']); + $ogLiveEntity->setKernel($ogLive['kernel']); + $ogLiveEntity->setRevision($ogLive['revision']); + $ogLiveEntity->setDirectory($ogLive['directory']); + $ogLiveEntity->setChecksum($ogLive['id']); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/OgLive/UninstallAction.php b/src/Controller/OgBoot/OgLive/UninstallAction.php index ac9f047..d0ea542 100644 --- a/src/Controller/OgBoot/OgLive/UninstallAction.php +++ b/src/Controller/OgBoot/OgLive/UninstallAction.php @@ -2,12 +2,14 @@ namespace App\Controller\OgBoot\OgLive; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\OgLive; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; +use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; @@ -15,7 +17,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class UninstallAction extends AbstractOgLiveController +class UninstallAction extends AbstractOgBootController { /** * @throws ServerExceptionInterface @@ -25,22 +27,14 @@ class UninstallAction extends AbstractOgLiveController */ public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { - try { - $response = $httpClient->request('DELETE', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum(), [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: $e->getMessage(), status: Response::HTTP_INTERNAL_SERVER_ERROR); + if (!$data->getChecksum()) { + throw new ValidatorException('Checksum is required'); } - if ($response->getStatusCode() === Response::HTTP_OK) { - $data->setInstalled(false); - $entityManager->persist($data); - $entityManager->flush(); - } + $content = $this->createRequest($httpClient, 'DELETE', $this->ogBootApiUrl.'/ogboot/v1/oglives/'.$data->getChecksum()); + + $entityManager->remove($data); + $entityManager->flush(); return new JsonResponse(status: Response::HTTP_OK); } diff --git a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php index f758745..f870364 100644 --- a/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php +++ b/src/Controller/OgBoot/PxeBootFile/GetCollectionAction.php @@ -2,7 +2,7 @@ namespace App\Controller\OgBoot\PxeBootFile; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\PxeBootFile; use App\Entity\PxeTemplate; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -16,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class GetCollectionAction extends AbstractOgLiveController +class GetCollectionAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -26,18 +26,8 @@ class GetCollectionAction extends AbstractOgLiveController */ public function __invoke(HttpClientInterface $httpClient): JsonResponse { - try { - $response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes', [ - 'headers' => [ - 'accept' => 'application/json', - ], - ]); - } catch (TransportExceptionInterface $e) { - return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); - } + $content = $this->createRequest($httpClient, 'GET', $this->ogBootApiUrl.'/ogboot/v1/pxes'); - $data = json_decode($response->getContent(), true); - - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse(data: $content, status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/PxeTemplate/DeleteAction.php b/src/Controller/OgBoot/PxeTemplate/DeleteAction.php index 4971708..ba6c49d 100644 --- a/src/Controller/OgBoot/PxeTemplate/DeleteAction.php +++ b/src/Controller/OgBoot/PxeTemplate/DeleteAction.php @@ -2,8 +2,9 @@ namespace App\Controller\OgBoot\PxeTemplate; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\PxeTemplate; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -15,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class DeleteAction extends AbstractOgLiveController +class DeleteAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface @@ -23,7 +24,7 @@ class DeleteAction extends AbstractOgLiveController * @throws RedirectionExceptionInterface * @throws ClientExceptionInterface */ - public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient): JsonResponse + public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse { try { $response = $httpClient->request('DELETE', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates/'.$data->getName(), [ @@ -35,8 +36,11 @@ class DeleteAction extends AbstractOgLiveController return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR); } - $data = json_decode($response->getContent(), true); + if ($response->getStatusCode() === Response::HTTP_OK) { + $entityManager->remove($data); + $entityManager->flush(); + } - return new JsonResponse( data: $data, status: Response::HTTP_OK); + return new JsonResponse(status: Response::HTTP_OK); } } \ No newline at end of file diff --git a/src/Controller/OgBoot/PxeTemplate/GetAction.php b/src/Controller/OgBoot/PxeTemplate/GetAction.php index 19e91a3..5648a55 100644 --- a/src/Controller/OgBoot/PxeTemplate/GetAction.php +++ b/src/Controller/OgBoot/PxeTemplate/GetAction.php @@ -2,7 +2,7 @@ namespace App\Controller\OgBoot\PxeTemplate; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\PxeTemplate; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -15,7 +15,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class GetAction extends AbstractOgLiveController +class GetAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface diff --git a/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php b/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php index 6693311..c294cae 100644 --- a/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php +++ b/src/Controller/OgBoot/PxeTemplate/GetCollectionAction.php @@ -2,7 +2,7 @@ namespace App\Controller\OgBoot\PxeTemplate; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -14,7 +14,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class GetCollectionAction extends AbstractOgLiveController +class GetCollectionAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface diff --git a/src/Controller/OgBoot/PxeTemplate/PostAction.php b/src/Controller/OgBoot/PxeTemplate/PostAction.php index d07a016..a448bf1 100644 --- a/src/Controller/OgBoot/PxeTemplate/PostAction.php +++ b/src/Controller/OgBoot/PxeTemplate/PostAction.php @@ -2,7 +2,7 @@ namespace App\Controller\OgBoot\PxeTemplate; -use App\Controller\OgBoot\AbstractOgLiveController; +use App\Controller\OgBoot\AbstractOgBootController; use App\Entity\PxeTemplate; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -16,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; #[AsController] -class PostAction extends AbstractOgLiveController +class PostAction extends AbstractOgBootController { /** * @throws TransportExceptionInterface