refs #423. New table and Endpoint Partition
parent
58d075ee46
commit
0e707f1d69
|
@ -0,0 +1,30 @@
|
|||
resources:
|
||||
App\Entity\Partition:
|
||||
processor: App\State\Processor\PartitionProcessor
|
||||
input: App\Dto\Input\PartitionInput
|
||||
output: App\Dto\Output\PartitionOutput
|
||||
normalization_context:
|
||||
groups: ['default', 'partition:read']
|
||||
denormalization_context:
|
||||
groups: ['partition:write']
|
||||
operations:
|
||||
ApiPlatform\Metadata\GetCollection:
|
||||
provider: App\State\Provider\PartitionProvider
|
||||
filters:
|
||||
- 'api_platform.filter.partition.order'
|
||||
- 'api_platform.filter.partition.search'
|
||||
ApiPlatform\Metadata\Get:
|
||||
provider: App\State\Provider\PartitionProvider
|
||||
ApiPlatform\Metadata\Put:
|
||||
provider: App\State\Provider\PartitionProvider
|
||||
ApiPlatform\Metadata\Patch:
|
||||
provider: App\State\Provider\PartitionProvider
|
||||
ApiPlatform\Metadata\Post: ~
|
||||
ApiPlatform\Metadata\Delete: ~
|
||||
|
||||
properties:
|
||||
App\Entity\Partition:
|
||||
id:
|
||||
identifier: false
|
||||
uuid:
|
||||
identifier: true
|
|
@ -59,3 +59,8 @@ services:
|
|||
bind:
|
||||
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
|
||||
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
|
||||
|
||||
App\State\Provider\PartitionProvider:
|
||||
bind:
|
||||
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
|
||||
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
|
|
@ -1,17 +1,74 @@
|
|||
services:
|
||||
api_platform.filter.client.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
$properties: { 'id': ~, 'name': ~, 'serialNumber': ~ }
|
||||
$orderParameterName: 'order'
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.client.search:
|
||||
parent: 'api_platform.doctrine.orm.search_filter'
|
||||
arguments: [ { 'id': 'exact', 'name': 'partial', 'serialNumber': 'exact' } ]
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.hardware.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
$properties: { 'id': ~, 'name': ~ }
|
||||
$orderParameterName: 'order'
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.hardware.search:
|
||||
parent: 'api_platform.doctrine.orm.search_filter'
|
||||
arguments: [ { 'id': 'exact', 'name': 'partial' } ]
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.menu.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
$properties: { 'id': ~, 'name': ~, 'title': ~ }
|
||||
$orderParameterName: 'order'
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.menu.search:
|
||||
parent: 'api_platform.doctrine.orm.search_filter'
|
||||
arguments: [ { 'id': 'exact', 'name': 'exact', 'title': 'exact' } ]
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
|
||||
api_platform.filter.partition.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
$properties: { 'id': ~, 'usage': ~ }
|
||||
$orderParameterName: 'order'
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.partition.search:
|
||||
parent: 'api_platform.doctrine.orm.search_filter'
|
||||
arguments: [ { 'id': 'exact', 'usage': 'exact', 'diskNumber': 'exact' } ]
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.user.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
$properties: { 'id' : ~, 'username': ~ }
|
||||
$properties: { 'id': ~, 'username': ~ }
|
||||
$orderParameterName: 'order'
|
||||
tags:
|
||||
- ['api_platform.filter' ]
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.user.search:
|
||||
parent: 'api_platform.doctrine.orm.search_filter'
|
||||
arguments: [ { 'id': 'exact', 'username': 'partial' }]
|
||||
arguments: [ { 'id': 'exact', 'username': 'partial' } ]
|
||||
tags:
|
||||
- ['api_platform.filter' ]
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.user.boolean:
|
||||
parent: 'api_platform.doctrine.orm.boolean_filter'
|
||||
|
@ -39,16 +96,4 @@ services:
|
|||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.hardware.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
$properties: { 'id': ~, 'name': ~ }
|
||||
$orderParameterName: 'order'
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.hardware.search:
|
||||
parent: 'api_platform.doctrine.orm.search_filter'
|
||||
arguments: [ { 'id': 'exact', 'name': 'partial' } ]
|
||||
tags:
|
||||
- [ 'api_platform.filter' ]
|
||||
|
|
|
@ -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 Version20240614082024 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('CREATE TABLE `partition` (id INT AUTO_INCREMENT NOT NULL, client_id INT DEFAULT NULL, uuid CHAR(36) NOT NULL COMMENT \'(DC2Type:uuid)\', migration_id VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by VARCHAR(255) DEFAULT NULL, updated_by VARCHAR(255) DEFAULT NULL, disk_number INT DEFAULT NULL, partition_number INT DEFAULT NULL, partition_code VARCHAR(255) DEFAULT NULL, size INT NOT NULL, cache_content VARCHAR(255) DEFAULT NULL, filesystem VARCHAR(255) DEFAULT NULL, os_name VARCHAR(255) NOT NULL, memory_usage INT NOT NULL, UNIQUE INDEX UNIQ_9EB910E4D17F50A6 (uuid), INDEX IDX_9EB910E419EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE `partition` ADD CONSTRAINT FK_9EB910E419EB6921 FOREIGN KEY (client_id) REFERENCES client (id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE `partition` DROP FOREIGN KEY FK_9EB910E419EB6921');
|
||||
$this->addSql('DROP TABLE `partition`');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?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 Version20240614082735 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 client DROP FOREIGN KEY FK_C7440455CCD7E912');
|
||||
$this->addSql('DROP INDEX IDX_C7440455CCD7E912 ON client');
|
||||
$this->addSql('ALTER TABLE client ADD menu VARCHAR(255) DEFAULT NULL, DROP menu_id');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE client ADD menu_id INT DEFAULT NULL, DROP menu');
|
||||
$this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C7440455CCD7E912 FOREIGN KEY (menu_id) REFERENCES menu (id)');
|
||||
$this->addSql('CREATE INDEX IDX_C7440455CCD7E912 ON client (menu_id)');
|
||||
}
|
||||
}
|
|
@ -51,7 +51,6 @@ final class ClientInput
|
|||
#[ApiProperty(description: 'The hardware profile of the client')]
|
||||
public ?HardwareProfileOutput $hardwareProfile = null;
|
||||
|
||||
#[Assert\NotNull]
|
||||
#[Groups(['client:write'])]
|
||||
#[ApiProperty(description: 'The menu of the client')]
|
||||
public ?MenuOutput $menu = null;
|
||||
|
@ -85,7 +84,11 @@ final class ClientInput
|
|||
$client->setNetiface($this->netiface);
|
||||
$client->setOrganizationalUnit($this->organizationalUnit->getEntity());
|
||||
$client->setHardwareProfile($this->hardwareProfile->getEntity());
|
||||
$client->setMenu($this->menu->getEntity());
|
||||
|
||||
if ($this->menu) {
|
||||
$client->setMenu($this->menu->getEntity());
|
||||
}
|
||||
|
||||
$client->setNetDriver($this->netDriver);
|
||||
$client->setMac($this->mac);
|
||||
$client->setIp($this->ip);
|
||||
|
|
|
@ -16,6 +16,7 @@ final class MenuInput
|
|||
#[ApiProperty(description: 'The name of the menu', example: "Menu 1")]
|
||||
public ?string $name = null;
|
||||
|
||||
#[Assert\NotNull()]
|
||||
#[Groups(['menu:write'])]
|
||||
#[ApiProperty(description: 'The title of the menu', example: "Menu 1 title")]
|
||||
public ?string $title = null;
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Dto\Output\OrganizationalUnitOutput;
|
||||
use App\Entity\HardwareProfile;
|
||||
use App\Entity\Menu;
|
||||
use App\Entity\Partition;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class PartitionInput
|
||||
{
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The disk number of the partition', example: 1)]
|
||||
public ?int $diskNumber = null;
|
||||
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The number of the partition', example: 1)]
|
||||
public ?int $partitionNumber = null;
|
||||
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The code of the partition', example: "code")]
|
||||
public ?string $partitionCode = null;
|
||||
|
||||
#[Assert\NotNull()]
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The size of the partition', example: 100)]
|
||||
public ?int $size = null;
|
||||
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The cache content of the partition', example: "cache content")]
|
||||
public ?string $cacheContent = null;
|
||||
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The filesystem of the partition', example: "filesystem")]
|
||||
public ?string $filesystem = null;
|
||||
|
||||
#[Assert\NotNull()]
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The operative system name of the partition', example: "Ubuntu")]
|
||||
public ?string $osName = null;
|
||||
|
||||
#[Assert\NotNull()]
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The client of the partition')]
|
||||
public ?ClientOutput $client = null;
|
||||
|
||||
#[Assert\NotNull()]
|
||||
#[Groups(['partition:write'])]
|
||||
#[ApiProperty(description: 'The memory usage of the partition', example: 100)]
|
||||
public ?int $memoryUsage = null;
|
||||
|
||||
public function __construct(?Partition $partition = null)
|
||||
{
|
||||
if (!$partition) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->diskNumber = $partition->getDiskNumber();
|
||||
$this->partitionNumber = $partition->getPartitionNumber();
|
||||
$this->partitionCode = $partition->getPartitionCode();
|
||||
$this->size = $partition->getSize();
|
||||
$this->cacheContent = $partition->getCacheContent();
|
||||
$this->filesystem = $partition->getFilesystem();
|
||||
$this->osName = $partition->getOsName();
|
||||
$this->client = new ClientOutput($partition->getClient());
|
||||
$this->memoryUsage = $partition->getMemoryUsage();
|
||||
}
|
||||
|
||||
public function createOrUpdateEntity(?Partition $partition = null): Partition
|
||||
{
|
||||
if (!$partition) {
|
||||
$partition = new Partition();
|
||||
}
|
||||
|
||||
$partition->setDiskNumber($this->diskNumber);
|
||||
$partition->setPartitionNumber($this->partitionNumber);
|
||||
$partition->setPartitionCode($this->partitionCode);
|
||||
$partition->setSize($this->size * 100);
|
||||
$partition->setCacheContent($this->cacheContent);
|
||||
$partition->setFilesystem($this->filesystem);
|
||||
$partition->setOsName($this->osName);
|
||||
$partition->setClient($this->client->getEntity());
|
||||
$partition->setMemoryUsage($this->memoryUsage * 100);
|
||||
|
||||
return $partition;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace App\Dto\Output;
|
|||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Entity\Client;
|
||||
use App\Entity\Partition;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
#[Get(shortName: 'Client')]
|
||||
|
@ -27,6 +28,12 @@ final class ClientOutput extends AbstractOutput
|
|||
#[Groups(['client:read'])]
|
||||
public ?MenuOutput $menu = null;
|
||||
|
||||
/**
|
||||
* @var Partition[]
|
||||
*/
|
||||
#[Groups(['client:read'])]
|
||||
public array $partitions = [];
|
||||
|
||||
#[Groups(['client:read'])]
|
||||
public \DateTime $createdAt;
|
||||
|
||||
|
@ -49,6 +56,11 @@ final class ClientOutput extends AbstractOutput
|
|||
if($client->getMenu()) {
|
||||
$this->menu = new MenuOutput($client->getMenu());
|
||||
}
|
||||
|
||||
foreach ($client->getPartitions() as $partition) {
|
||||
$this->partitions[] = new PartitionOutput($partition);
|
||||
}
|
||||
|
||||
$this->createdAt = $client->getCreatedAt();
|
||||
$this->createdBy = $client->getCreatedBy();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Output;
|
||||
|
||||
use App\Entity\Partition;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
class PartitionOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['partition:read'])]
|
||||
public ?int $diskNumber = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?string $partitionNumber = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?string $partitionCode = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?int $size = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?string $cacheContent = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?string $filesystem = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?string $osName = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?ClientOutput $client = null;
|
||||
|
||||
#[Groups(['partition:read'])]
|
||||
public ?int $memoryUsage = null;
|
||||
|
||||
public function __construct(Partition $partition)
|
||||
{
|
||||
parent::__construct($partition);
|
||||
|
||||
$this->diskNumber = $partition->getDiskNumber();
|
||||
$this->partitionNumber = $partition->getPartitionNumber();
|
||||
$this->partitionCode = $partition->getPartitionCode();
|
||||
$this->size = $partition->getSize() / 100;
|
||||
$this->cacheContent = $partition->getCacheContent();
|
||||
$this->filesystem = $partition->getFilesystem();
|
||||
$this->osName = $partition->getOsName();
|
||||
$this->client = new ClientOutput($partition->getClient());
|
||||
$this->memoryUsage = $partition->getMemoryUsage() / 100;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ClientRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ClientRepository::class)]
|
||||
|
@ -35,8 +37,21 @@ class Client extends AbstractEntity
|
|||
private ?HardwareProfile $hardwareProfile = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'clients')]
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?Menu $menu = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Partition>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'client', targetEntity: Partition::class)]
|
||||
private Collection $partitions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->partitions = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getSerialNumber(): ?string
|
||||
{
|
||||
return $this->serialNumber;
|
||||
|
@ -144,4 +159,34 @@ class Client extends AbstractEntity
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Partition>
|
||||
*/
|
||||
public function getPartitions(): Collection
|
||||
{
|
||||
return $this->partitions;
|
||||
}
|
||||
|
||||
public function addPartition(Partition $partition): static
|
||||
{
|
||||
if (!$this->partitions->contains($partition)) {
|
||||
$this->partitions->add($partition);
|
||||
$partition->setClient($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removePartition(Partition $partition): static
|
||||
{
|
||||
if ($this->partitions->removeElement($partition)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($partition->getClient() === $this) {
|
||||
$partition->setClient(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PartitionRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PartitionRepository::class)]
|
||||
#[ORM\Table(name: '`partition`')]
|
||||
class Partition extends AbstractEntity
|
||||
{
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $diskNumber = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $partitionNumber = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $partitionCode = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $size = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $cacheContent = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $filesystem = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $osName = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'partitions')]
|
||||
private ?Client $client = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $memoryUsage = null;
|
||||
|
||||
public function getDiskNumber(): ?int
|
||||
{
|
||||
return $this->diskNumber;
|
||||
}
|
||||
|
||||
public function setDiskNumber(?int $diskNumber): static
|
||||
{
|
||||
$this->diskNumber = $diskNumber;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPartitionNumber(): ?int
|
||||
{
|
||||
return $this->partitionNumber;
|
||||
}
|
||||
|
||||
public function setPartitionNumber(?int $partitionNumber): static
|
||||
{
|
||||
$this->partitionNumber = $partitionNumber;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPartitionCode(): ?string
|
||||
{
|
||||
return $this->partitionCode;
|
||||
}
|
||||
|
||||
public function setPartitionCode(?string $partitionCode): static
|
||||
{
|
||||
$this->partitionCode = $partitionCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(): ?int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function setSize(int $size): static
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCacheContent(): ?string
|
||||
{
|
||||
return $this->cacheContent;
|
||||
}
|
||||
|
||||
public function setCacheContent(?string $cacheContent): static
|
||||
{
|
||||
$this->cacheContent = $cacheContent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFilesystem(): ?string
|
||||
{
|
||||
return $this->filesystem;
|
||||
}
|
||||
|
||||
public function setFilesystem(?string $filesystem): static
|
||||
{
|
||||
$this->filesystem = $filesystem;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOsName(): ?string
|
||||
{
|
||||
return $this->osName;
|
||||
}
|
||||
|
||||
public function setOsName(string $osName): static
|
||||
{
|
||||
$this->osName = $osName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClient(): ?Client
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
public function setClient(?Client $client): static
|
||||
{
|
||||
$this->client = $client;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMemoryUsage(): ?int
|
||||
{
|
||||
return $this->memoryUsage;
|
||||
}
|
||||
|
||||
public function setMemoryUsage(int $memoryUsage): static
|
||||
{
|
||||
$this->memoryUsage = $memoryUsage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Partition;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Partition>
|
||||
*/
|
||||
class PartitionRepository extends AbstractRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Partition::class);
|
||||
}
|
||||
}
|
|
@ -52,11 +52,11 @@ class HardwareProcessor implements ProcessorInterface
|
|||
$entity = $this->hardwareRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$userGroup = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($userGroup);
|
||||
$this->hardwareRepository->save($userGroup);
|
||||
$hardware = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($hardware);
|
||||
$this->hardwareRepository->save($hardware);
|
||||
|
||||
return new HardwareOutput($userGroup);
|
||||
return new HardwareOutput($hardware);
|
||||
}
|
||||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
|
|
|
@ -17,8 +17,8 @@ use App\Repository\HardwareProfileRepository;
|
|||
readonly class HardwareProfileProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private HardwareProfileRepository $hardwareProfileRepository,
|
||||
private ValidatorInterface $validator
|
||||
private HardwareProfileRepository $hardwareProfileRepository,
|
||||
private ValidatorInterface $validator
|
||||
)
|
||||
{
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ readonly class HardwareProfileProcessor implements ProcessorInterface
|
|||
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): HardwareProfileOutput
|
||||
{
|
||||
if (!($data instanceof HardwareProfileInput)) {
|
||||
throw new \Exception(sprintf('data is not instance of %s', HardwareInput::class));
|
||||
throw new \Exception(sprintf('data is not instance of %s', HardwareProfileInput::class));
|
||||
}
|
||||
|
||||
$entity = null;
|
||||
|
@ -52,11 +52,11 @@ readonly class HardwareProfileProcessor implements ProcessorInterface
|
|||
$entity = $this->hardwareProfileRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$userGroup = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($userGroup);
|
||||
$this->hardwareProfileRepository->save($userGroup);
|
||||
$hardwareProfile = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($hardwareProfile);
|
||||
$this->hardwareProfileRepository->save($hardwareProfile);
|
||||
|
||||
return new HardwareProfileOutput($userGroup);
|
||||
return new HardwareProfileOutput($hardwareProfile);
|
||||
}
|
||||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
|
|
|
@ -16,11 +16,11 @@ use App\Dto\Output\UserGroupOutput;
|
|||
use App\Repository\MenuRepository;
|
||||
use App\Repository\UserGroupRepository;
|
||||
|
||||
class MenuProcessor implements ProcessorInterface
|
||||
readonly class MenuProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly MenuRepository $menuRepository,
|
||||
private readonly ValidatorInterface $validator
|
||||
private MenuRepository $menuRepository,
|
||||
private ValidatorInterface $validator
|
||||
)
|
||||
{
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class MenuProcessor implements ProcessorInterface
|
|||
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): MenuOutput
|
||||
{
|
||||
if (!($data instanceof MenuInput)) {
|
||||
throw new \Exception(sprintf('data is not instance of %s', UserGroupInput::class));
|
||||
throw new \Exception(sprintf('data is not instance of %s', MenuInput::class));
|
||||
}
|
||||
|
||||
$entity = null;
|
||||
|
@ -54,11 +54,11 @@ class MenuProcessor implements ProcessorInterface
|
|||
$entity = $this->menuRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$userGroup = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($userGroup);
|
||||
$this->menuRepository->save($userGroup);
|
||||
$menu = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($menu);
|
||||
$this->menuRepository->save($menu);
|
||||
|
||||
return new MenuOutput($userGroup);
|
||||
return new MenuOutput($menu);
|
||||
}
|
||||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace App\State\Processor;
|
||||
|
||||
use ApiPlatform\Metadata\Delete;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use ApiPlatform\Validator\ValidatorInterface;
|
||||
use App\Dto\Input\MenuInput;
|
||||
use App\Dto\Input\PartitionInput;
|
||||
use App\Dto\Input\UserGroupInput;
|
||||
use App\Dto\Output\MenuOutput;
|
||||
use App\Dto\Output\PartitionOutput;
|
||||
use App\Dto\Output\UserGroupOutput;
|
||||
use App\Repository\MenuRepository;
|
||||
use App\Repository\PartitionRepository;
|
||||
use App\Repository\UserGroupRepository;
|
||||
|
||||
readonly class PartitionProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private PartitionRepository $partitionRepository,
|
||||
private ValidatorInterface $validator
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): PartitionOutput|null
|
||||
{
|
||||
switch ($operation){
|
||||
case $operation instanceof Post:
|
||||
case $operation instanceof Put:
|
||||
case $operation instanceof Patch:
|
||||
return $this->processCreateOrUpdate($data, $operation, $uriVariables, $context);
|
||||
case $operation instanceof Delete:
|
||||
return $this->processDelete($data, $operation, $uriVariables, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function processCreateOrUpdate($data, Operation $operation, array $uriVariables = [], array $context = []): PartitionOutput
|
||||
{
|
||||
if (!($data instanceof PartitionInput)) {
|
||||
throw new \Exception(sprintf('data is not instance of %s', PartitionInput::class));
|
||||
}
|
||||
|
||||
$entity = null;
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$entity = $this->partitionRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$partition = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($partition);
|
||||
$this->partitionRepository->save($partition);
|
||||
|
||||
return new PartitionOutput($partition);
|
||||
}
|
||||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
{
|
||||
$user = $this->partitionRepository->findOneByUuid($uriVariables['uuid']);
|
||||
$this->partitionRepository->delete($user);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace App\State\Provider;
|
||||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Metadata\Patch;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use ApiPlatform\State\Pagination\TraversablePaginator;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Dto\Input\ClientInput;
|
||||
use App\Dto\Input\HardwareInput;
|
||||
use App\Dto\Input\MenuInput;
|
||||
use App\Dto\Input\PartitionInput;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Dto\Output\HardwareOutput;
|
||||
use App\Dto\Output\MenuOutput;
|
||||
use App\Dto\Output\PartitionOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class PartitionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProviderInterface $collectionProvider,
|
||||
private readonly ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
switch ($operation){
|
||||
case $operation instanceof GetCollection:
|
||||
return $this->provideCollection($operation, $uriVariables, $context);
|
||||
case $operation instanceof Patch:
|
||||
case $operation instanceof Put:
|
||||
return $this->provideInput($operation, $uriVariables, $context);
|
||||
case $operation instanceof Get:
|
||||
return $this->provideItem($operation, $uriVariables, $context);
|
||||
}
|
||||
}
|
||||
|
||||
private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object
|
||||
{
|
||||
$paginator = $this->collectionProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
$items = new \ArrayObject();
|
||||
foreach ($paginator->getIterator() as $item){
|
||||
$items[] = new PartitionOutput($item);
|
||||
}
|
||||
|
||||
return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems());
|
||||
}
|
||||
|
||||
public function provideItem(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
if (!$item) {
|
||||
throw new NotFoundHttpException('Partition not found');
|
||||
}
|
||||
|
||||
return new PartitionOutput($item);
|
||||
}
|
||||
|
||||
public function provideInput(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
|
||||
|
||||
return $item !== null ? new PartitionInput($item) : null;
|
||||
}
|
||||
|
||||
return new PartitionInput();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue