refs #632. Create new fields and updated API
parent
f483b94a70
commit
36863bff7b
|
@ -9,20 +9,29 @@ resources:
|
|||
groups: ['pxe-boot-file:write']
|
||||
operations:
|
||||
ApiPlatform\Metadata\GetCollection:
|
||||
provider: App\State\Provider\PPxeBootFileProvider
|
||||
provider: App\State\Provider\PxeBootFileProvider
|
||||
filters:
|
||||
- 'api_platform.filter.pxe_boot_file.order'
|
||||
- 'api_platform.filter.pxe_boot_file.search'
|
||||
|
||||
ApiPlatform\Metadata\Get:
|
||||
provider: App\State\Provider\PxeTemplateProvider
|
||||
provider: App\State\Provider\PxeBootFileProvider
|
||||
ApiPlatform\Metadata\Put:
|
||||
provider: App\State\Provider\PxeTemplateProvider
|
||||
provider: App\State\Provider\PxeBootFileProvider
|
||||
ApiPlatform\Metadata\Patch:
|
||||
provider: App\State\Provider\PxeTemplateProvider
|
||||
provider: App\State\Provider\PxeBootFileProvider
|
||||
ApiPlatform\Metadata\Post: ~
|
||||
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:
|
||||
App\Entity\PxeBootFile:
|
||||
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\Entity\OgLive;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
|
@ -22,7 +23,7 @@ class InstallAction extends AbstractOgLiveController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient): JsonResponse
|
||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/oglives/install', [
|
||||
|
@ -31,13 +32,17 @@ class InstallAction extends AbstractOgLiveController
|
|||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => [
|
||||
'isoname' => $data->getName()
|
||||
'url' => $data->getDownloadUrl()
|
||||
]
|
||||
]);
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
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);
|
||||
|
||||
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\Entity\OgLive;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
|
@ -22,7 +23,7 @@ class SetDefaultAction extends AbstractOgLiveController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient): JsonResponse
|
||||
public function __invoke(OgLive $data, HttpClientInterface $httpClient, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
try {
|
||||
$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);
|
||||
}
|
||||
|
||||
$data->setDefault(true);
|
||||
$entityManager->persist($data);
|
||||
$entityManager->flush();
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
|
||||
return new JsonResponse( data: $data, status: Response::HTTP_OK);
|
||||
|
|
|
@ -16,7 +16,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsController]
|
||||
class GetAction extends AbstractOgLiveController
|
||||
class GetCollectionAction extends AbstractOgLiveController
|
||||
{
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
|
@ -27,7 +27,7 @@ class GetAction extends AbstractOgLiveController
|
|||
public function __invoke(PxeBootFile $data, HttpClientInterface $httpClient): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes/'.$data->getName(), [
|
||||
$response = $httpClient->request('GET', $this->ogBootApiUrl.'/ogboot/v1/pxes', [
|
||||
'headers' => [
|
||||
'accept' => 'application/json',
|
||||
],
|
|
@ -4,6 +4,7 @@ namespace App\Controller\OgBoot\PxeTemplate;
|
|||
|
||||
use App\Controller\OgBoot\AbstractOgLiveController;
|
||||
use App\Entity\PxeTemplate;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -23,7 +24,7 @@ class PostAction 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('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);
|
||||
return new JsonResponse($data, Response::HTTP_OK);
|
||||
|
||||
|
|
|
@ -16,6 +16,12 @@ final class OgLiveOutput extends AbstractOutput
|
|||
#[Groups(['og-live:read'])]
|
||||
public ?bool $synchronized = false;
|
||||
|
||||
#[Groups(['og-live:read'])]
|
||||
public ?bool $installed = false;
|
||||
|
||||
#[Groups(['og-live:read'])]
|
||||
public ?bool $default = false;
|
||||
|
||||
#[Groups(['og-live:read'])]
|
||||
public ?string $downloadUrl = '';
|
||||
|
||||
|
@ -31,6 +37,8 @@ final class OgLiveOutput extends AbstractOutput
|
|||
|
||||
$this->name = $ogLive->getName();
|
||||
$this->synchronized = $ogLive->isSynchronized();
|
||||
$this->installed = $ogLive->isInstalled();
|
||||
$this->default = $ogLive->isDefault();
|
||||
$this->downloadUrl = $ogLive->getDownloadUrl();
|
||||
$this->createdAt = $ogLive->getCreatedAt();
|
||||
$this->createdBy = $ogLive->getCreatedBy();
|
||||
|
|
|
@ -17,6 +17,9 @@ final class PxeBootFileOutput extends AbstractOutput
|
|||
#[Groups(['pxe-boot-file:read'])]
|
||||
public array $clients;
|
||||
|
||||
#[Groups(['pxe-boot-file:read'])]
|
||||
public ?bool $synchronized = null;
|
||||
|
||||
#[Groups(['pxe-boot-file:read'])]
|
||||
public \DateTime $createdAt;
|
||||
|
||||
|
@ -32,6 +35,7 @@ final class PxeBootFileOutput extends AbstractOutput
|
|||
fn(Client $client) => new ClientOutput($client)
|
||||
)->toArray();
|
||||
|
||||
$this->synchronized = $bootFile->isSynchronized();
|
||||
$this->createdAt = $bootFile->getCreatedAt();
|
||||
$this->createdBy = $bootFile->getCreatedBy();
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ class OgLive extends AbstractEntity
|
|||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $installed = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $default = null;
|
||||
|
||||
public function getDownloadUrl(): ?string
|
||||
{
|
||||
return $this->downloadUrl;
|
||||
|
@ -148,4 +151,16 @@ class OgLive extends AbstractEntity
|
|||
|
||||
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)]
|
||||
class PxeBootFile extends AbstractEntity
|
||||
{
|
||||
use SynchronizedTrait;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
private ?PxeTemplate $template = null;
|
||||
|
||||
|
|
Loading…
Reference in New Issue