refs #632. Create new fields and updated API
parent
f483b94a70
commit
36863bff7b
|
@ -9,20 +9,29 @@ resources:
|
||||||
groups: ['pxe-boot-file:write']
|
groups: ['pxe-boot-file:write']
|
||||||
operations:
|
operations:
|
||||||
ApiPlatform\Metadata\GetCollection:
|
ApiPlatform\Metadata\GetCollection:
|
||||||
provider: App\State\Provider\PPxeBootFileProvider
|
provider: App\State\Provider\PxeBootFileProvider
|
||||||
filters:
|
filters:
|
||||||
- 'api_platform.filter.pxe_boot_file.order'
|
- 'api_platform.filter.pxe_boot_file.order'
|
||||||
- 'api_platform.filter.pxe_boot_file.search'
|
- 'api_platform.filter.pxe_boot_file.search'
|
||||||
|
|
||||||
ApiPlatform\Metadata\Get:
|
ApiPlatform\Metadata\Get:
|
||||||
provider: App\State\Provider\PxeTemplateProvider
|
provider: App\State\Provider\PxeBootFileProvider
|
||||||
ApiPlatform\Metadata\Put:
|
ApiPlatform\Metadata\Put:
|
||||||
provider: App\State\Provider\PxeTemplateProvider
|
provider: App\State\Provider\PxeBootFileProvider
|
||||||
ApiPlatform\Metadata\Patch:
|
ApiPlatform\Metadata\Patch:
|
||||||
provider: App\State\Provider\PxeTemplateProvider
|
provider: App\State\Provider\PxeBootFileProvider
|
||||||
ApiPlatform\Metadata\Post: ~
|
ApiPlatform\Metadata\Post: ~
|
||||||
ApiPlatform\Metadata\Delete: ~
|
ApiPlatform\Metadata\Delete: ~
|
||||||
|
|
||||||
|
get_collection:
|
||||||
|
shortName: PxeBootFile Server
|
||||||
|
description: Get collection of PxeBootFile
|
||||||
|
class: ApiPlatform\Metadata\GetCollection
|
||||||
|
method: GET
|
||||||
|
input: false
|
||||||
|
uriTemplate: /pxe-boot-files/server/get-collection
|
||||||
|
controller: App\Controller\OgBoot\PxeBootFile\GetCollectionAction
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
App\Entity\PxeBootFile:
|
App\Entity\PxeBootFile:
|
||||||
id:
|
id:
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20240819140045 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE og_live ADD `default` TINYINT(1) DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE pxe_boot_file ADD synchronized TINYINT(1) DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE og_live DROP `default`');
|
||||||
|
$this->addSql('ALTER TABLE pxe_boot_file DROP synchronized');
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgLiveController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
@ -22,7 +23,7 @@ class InstallAction extends AbstractOgLiveController
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', [
|
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', [
|
||||||
|
@ -31,13 +32,17 @@ class InstallAction extends AbstractOgLiveController
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
],
|
],
|
||||||
'json' => [
|
'json' => [
|
||||||
'isoname' => $data->getName()
|
'url' => $data->getDownloadUrl()
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
} catch (TransportExceptionInterface $e) {
|
} catch (TransportExceptionInterface $e) {
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data->setInstalled(true);
|
||||||
|
$entityManager->persist($data);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
$data = json_decode($response->getContent(), true);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Controller\OgBoot\OgLive;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgLiveController;
|
||||||
use App\Entity\OgLive;
|
use App\Entity\OgLive;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
@ -22,7 +23,7 @@ class SetDefaultAction extends AbstractOgLiveController
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', [
|
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/default', [
|
||||||
|
@ -37,6 +38,10 @@ class SetDefaultAction extends AbstractOgLiveController
|
||||||
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data->setDefault(true);
|
||||||
|
$entityManager->persist($data);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
$data = json_decode($response->getContent(), true);
|
||||||
|
|
||||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
||||||
|
|
|
@ -16,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
#[AsController]
|
#[AsController]
|
||||||
class GetAction extends AbstractOgLiveController
|
class GetCollectionAction extends AbstractOgLiveController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
|
@ -27,7 +27,7 @@ class GetAction extends AbstractOgLiveController
|
||||||
public function __invoke(PxeBootFile $data, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(PxeBootFile $data, HttpClientInterface $httpClient): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes/'.$data->getName(), [
|
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes', [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'accept' => 'application/json',
|
'accept' => 'application/json',
|
||||||
],
|
],
|
|
@ -4,6 +4,7 @@ namespace App\Controller\OgBoot\PxeTemplate;
|
||||||
|
|
||||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
use App\Controller\OgBoot\AbstractOgLiveController;
|
||||||
use App\Entity\PxeTemplate;
|
use App\Entity\PxeTemplate;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -23,7 +24,7 @@ class PostAction extends AbstractOgLiveController
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient): JsonResponse
|
public function __invoke(PxeTemplate $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [
|
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxe-templates', [
|
||||||
|
@ -37,6 +38,10 @@ class PostAction extends AbstractOgLiveController
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$data->setSynchronized(true);
|
||||||
|
$entityManager->persist($data);
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
$data = json_decode($response->getContent(), true);
|
$data = json_decode($response->getContent(), true);
|
||||||
return new JsonResponse($data, Response::HTTP_OK);
|
return new JsonResponse($data, Response::HTTP_OK);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,12 @@ final class OgLiveOutput extends AbstractOutput
|
||||||
#[Groups(['og-live:read'])]
|
#[Groups(['og-live:read'])]
|
||||||
public ?bool $synchronized = false;
|
public ?bool $synchronized = false;
|
||||||
|
|
||||||
|
#[Groups(['og-live:read'])]
|
||||||
|
public ?bool $installed = false;
|
||||||
|
|
||||||
|
#[Groups(['og-live:read'])]
|
||||||
|
public ?bool $default = false;
|
||||||
|
|
||||||
#[Groups(['og-live:read'])]
|
#[Groups(['og-live:read'])]
|
||||||
public ?string $downloadUrl = '';
|
public ?string $downloadUrl = '';
|
||||||
|
|
||||||
|
@ -31,6 +37,8 @@ final class OgLiveOutput extends AbstractOutput
|
||||||
|
|
||||||
$this->name = $ogLive->getName();
|
$this->name = $ogLive->getName();
|
||||||
$this->synchronized = $ogLive->isSynchronized();
|
$this->synchronized = $ogLive->isSynchronized();
|
||||||
|
$this->installed = $ogLive->isInstalled();
|
||||||
|
$this->default = $ogLive->isDefault();
|
||||||
$this->downloadUrl = $ogLive->getDownloadUrl();
|
$this->downloadUrl = $ogLive->getDownloadUrl();
|
||||||
$this->createdAt = $ogLive->getCreatedAt();
|
$this->createdAt = $ogLive->getCreatedAt();
|
||||||
$this->createdBy = $ogLive->getCreatedBy();
|
$this->createdBy = $ogLive->getCreatedBy();
|
||||||
|
|
|
@ -17,6 +17,9 @@ final class PxeBootFileOutput extends AbstractOutput
|
||||||
#[Groups(['pxe-boot-file:read'])]
|
#[Groups(['pxe-boot-file:read'])]
|
||||||
public array $clients;
|
public array $clients;
|
||||||
|
|
||||||
|
#[Groups(['pxe-boot-file:read'])]
|
||||||
|
public ?bool $synchronized = null;
|
||||||
|
|
||||||
#[Groups(['pxe-boot-file:read'])]
|
#[Groups(['pxe-boot-file:read'])]
|
||||||
public \DateTime $createdAt;
|
public \DateTime $createdAt;
|
||||||
|
|
||||||
|
@ -32,6 +35,7 @@ final class PxeBootFileOutput extends AbstractOutput
|
||||||
fn(Client $client) => new ClientOutput($client)
|
fn(Client $client) => new ClientOutput($client)
|
||||||
)->toArray();
|
)->toArray();
|
||||||
|
|
||||||
|
$this->synchronized = $bootFile->isSynchronized();
|
||||||
$this->createdAt = $bootFile->getCreatedAt();
|
$this->createdAt = $bootFile->getCreatedAt();
|
||||||
$this->createdBy = $bootFile->getCreatedBy();
|
$this->createdBy = $bootFile->getCreatedBy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ class OgLive extends AbstractEntity
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
private ?bool $installed = null;
|
private ?bool $installed = null;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
private ?bool $default = null;
|
||||||
|
|
||||||
public function getDownloadUrl(): ?string
|
public function getDownloadUrl(): ?string
|
||||||
{
|
{
|
||||||
return $this->downloadUrl;
|
return $this->downloadUrl;
|
||||||
|
@ -148,4 +151,16 @@ class OgLive extends AbstractEntity
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isDefault(): ?bool
|
||||||
|
{
|
||||||
|
return $this->default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDefault(?bool $default): static
|
||||||
|
{
|
||||||
|
$this->default = $default;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
#[ORM\Entity(repositoryClass: PxeBootFileRepository::class)]
|
#[ORM\Entity(repositoryClass: PxeBootFileRepository::class)]
|
||||||
class PxeBootFile extends AbstractEntity
|
class PxeBootFile extends AbstractEntity
|
||||||
{
|
{
|
||||||
|
use SynchronizedTrait;
|
||||||
|
|
||||||
#[ORM\ManyToOne]
|
#[ORM\ManyToOne]
|
||||||
private ?PxeTemplate $template = null;
|
private ?PxeTemplate $template = null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue