refs #487. Added image model and endpoint
parent
406f135804
commit
04b3bb72c7
|
@ -0,0 +1,30 @@
|
|||
resources:
|
||||
App\Entity\Image:
|
||||
processor: App\State\Processor\ImageProcessor
|
||||
input: App\Dto\Input\ImageInput
|
||||
output: App\Dto\Output\ImageOutput
|
||||
normalizationContext:
|
||||
groups: ['default', 'image:read']
|
||||
denormalizationContext:
|
||||
groups: ['image:write']
|
||||
operations:
|
||||
ApiPlatform\Metadata\GetCollection:
|
||||
provider: App\State\Provider\ImageProvider
|
||||
filters:
|
||||
- 'api_platform.filter.image.order'
|
||||
- 'api_platform.filter.image.search'
|
||||
ApiPlatform\Metadata\Get:
|
||||
provider: App\State\Provider\ImageProvider
|
||||
ApiPlatform\Metadata\Put:
|
||||
provider: App\State\Provider\ImageProvider
|
||||
ApiPlatform\Metadata\Patch:
|
||||
provider: App\State\Provider\ImageProvider
|
||||
ApiPlatform\Metadata\Post: ~
|
||||
ApiPlatform\Metadata\Delete: ~
|
||||
|
||||
properties:
|
||||
App\Entity\Image:
|
||||
id:
|
||||
identifier: false
|
||||
uuid:
|
||||
identifier: true
|
|
@ -82,3 +82,8 @@ services:
|
|||
bind:
|
||||
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
|
||||
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
|
||||
|
||||
App\State\Provider\ImageProvider:
|
||||
bind:
|
||||
$collectionProvider: '@api_platform.doctrine.orm.state.collection_provider'
|
||||
$itemProvider: '@api_platform.doctrine.orm.state.item_provider'
|
||||
|
|
|
@ -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 Version20240703090301 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 image (id INT AUTO_INCREMENT NOT NULL, client_id INT NOT NULL, software_profile_id INT NOT 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, description VARCHAR(255) DEFAULT NULL, comments VARCHAR(255) DEFAULT NULL, path VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, revision VARCHAR(255) DEFAULT NULL, info VARCHAR(255) DEFAULT NULL, size INT NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_C53D045FD17F50A6 (uuid), INDEX IDX_C53D045F19EB6921 (client_id), INDEX IDX_C53D045FED42A742 (software_profile_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)');
|
||||
$this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FED42A742 FOREIGN KEY (software_profile_id) REFERENCES software_profile (id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F19EB6921');
|
||||
$this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045FED42A742');
|
||||
$this->addSql('DROP TABLE image');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command\Migration;
|
||||
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Entity\Software;
|
||||
use App\Entity\SoftwareProfile;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'opengnsys:migrate-software-profile', description: 'Migrate software and software profile data')]
|
||||
class MigrateSoftwareAndSoftwareProfileCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly ManagerRegistry $doctrine
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
/** @var EntityManagerInterface $oldDatabaseEntityManager */
|
||||
$oldDatabaseEntityManager = $this->doctrine->getManager('og_1');
|
||||
|
||||
$organizationalUnitRepository = $this->entityManager->getRepository(OrganizationalUnit::class);
|
||||
$softwareProfileRepository = $this->entityManager->getRepository(SoftwareProfile::class);
|
||||
$softwareRepository = $this->entityManager->getRepository(Software::class);
|
||||
|
||||
/** Obtener los perfiles software de la base de datos antigua **/
|
||||
$rsmSoftware = new ResultSetMapping();
|
||||
$rsmSoftware->addScalarResult('idtiposoftware', 'idtiposoftware');
|
||||
$rsmSoftware->addScalarResult('descripcion', 'descripcion');
|
||||
|
||||
$softwareQuery = $oldDatabaseEntityManager->createNativeQuery('SELECT idtiposoftware, descripcion FROM softwares', $rsmSoftware);
|
||||
$softwareCollection = $softwareQuery->getResult();
|
||||
|
||||
foreach ($softwareCollection as $software) {
|
||||
$softwareEntity = null;
|
||||
$softwareEntity = $softwareRepository->findOneBy(['migrationId' => $software['idtiposoftware']]);
|
||||
if (!$softwareEntity) {
|
||||
$softwareEntity = new Software();
|
||||
$softwareEntity->setMigrationId($software['idtiposoftware']);
|
||||
$softwareEntity->setName($software['descripcion']);
|
||||
$softwareEntity->setDescription($software['descripcion']);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($softwareEntity);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Input;
|
||||
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Dto\Output\SoftwareProfileOutput;
|
||||
use App\Entity\Image;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class ImageInput
|
||||
{
|
||||
#[Assert\NotBlank]
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The name of the image', example: "Image 1")]
|
||||
public ?string $name = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The description of the image', example: "Image 1 description")]
|
||||
public ?string $description = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The comments of the image', example: "Image 1 comments")]
|
||||
public ?string $comments = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The type of the image', example: "Server")]
|
||||
public ?string $type = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The path of the image', example: "/path/to/image")]
|
||||
public ?string $path = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The revision of the image', example: "1.0")]
|
||||
public ?string $revision = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The info of the image', example: "Image 1 info")]
|
||||
public ?string $info = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The size of the image', example: 1024)]
|
||||
public ?int $size = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The client of the image')]
|
||||
public ?ClientOutput $client = null;
|
||||
|
||||
#[Groups(['image:write'])]
|
||||
#[ApiProperty(description: 'The software profile of the image')]
|
||||
public ?SoftwareProfileOutput $softwareProfile = null;
|
||||
|
||||
public function __construct(?Image $image = null)
|
||||
{
|
||||
if (!$image) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->name = $image->getName();
|
||||
$this->description = $image->getDescription();
|
||||
$this->comments = $image->getComments();
|
||||
$this->type = $image->getType();
|
||||
$this->path = $image->getPath();
|
||||
$this->revision = $image->getRevision();
|
||||
$this->info = $image->getInfo();
|
||||
$this->size = $image->getSize();
|
||||
$this->client = new ClientOutput($image->getClient());
|
||||
$this->softwareProfile = new SoftwareProfileOutput($image->getSoftwareProfile());
|
||||
}
|
||||
|
||||
public function createOrUpdateEntity(?Image $image = null): Image
|
||||
{
|
||||
if (!$image) {
|
||||
$image = new Image();
|
||||
}
|
||||
|
||||
$image->setName($this->name);
|
||||
$image->setDescription($this->description);
|
||||
$image->setComments($this->comments);
|
||||
$image->setType($this->type);
|
||||
$image->setPath($this->path);
|
||||
$image->setRevision($this->revision);
|
||||
$image->setInfo($this->info);
|
||||
$image->setSize($this->size);
|
||||
$image->setClient($this->client->getEntity());
|
||||
$image->setSoftwareProfile($this->softwareProfile->getEntity());
|
||||
|
||||
return $image;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Dto\Output;
|
||||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Entity\Image;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
||||
#[Get(shortName: 'Image')]
|
||||
final class ImageOutput extends AbstractOutput
|
||||
{
|
||||
#[Groups(['image:read'])]
|
||||
public ?string $name = '';
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?string $description = '';
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?string $comments = '';
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?string $type = '';
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?string $path = '';
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?string $revision = '';
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?string $info = '';
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?int $size = null;
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?ClientOutput $clientOutput = null;
|
||||
|
||||
#[Groups(['image:read'])]
|
||||
public ?SoftwareProfileOutput $softwareProfile = null;
|
||||
|
||||
public function __construct(Image $image)
|
||||
{
|
||||
parent::__construct($image);
|
||||
|
||||
$this->name = $image->getName();
|
||||
$this->description = $image->getDescription();
|
||||
$this->comments = $image->getComments();
|
||||
$this->type = $image->getType();
|
||||
$this->path = $image->getPath();
|
||||
$this->revision = $image->getRevision();
|
||||
$this->info = $image->getInfo();
|
||||
$this->size = $image->getSize();
|
||||
$this->clientOutput = new ClientOutput($image->getClient());
|
||||
$this->softwareProfile = new SoftwareProfileOutput($image->getSoftwareProfile());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ImageRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ImageRepository::class)]
|
||||
class Image extends AbstractEntity
|
||||
{
|
||||
use NameableTrait;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $comments = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $path = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $type = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $revision = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $info = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $size = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Client $client = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?SoftwareProfile $softwareProfile = null;
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setDescription(?string $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getComments(): ?string
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function setComments(?string $comments): static
|
||||
{
|
||||
$this->comments = $comments;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPath(): ?string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath(string $path): static
|
||||
{
|
||||
$this->path = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType(string $type): static
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRevision(): ?string
|
||||
{
|
||||
return $this->revision;
|
||||
}
|
||||
|
||||
public function setRevision(?string $revision): static
|
||||
{
|
||||
$this->revision = $revision;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInfo(): ?string
|
||||
{
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
public function setInfo(?string $info): static
|
||||
{
|
||||
$this->info = $info;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(): ?int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function setSize(int $size): static
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClient(): ?Client
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
public function setClient(?Client $client): static
|
||||
{
|
||||
$this->client = $client;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSoftwareProfile(): ?SoftwareProfile
|
||||
{
|
||||
return $this->softwareProfile;
|
||||
}
|
||||
|
||||
public function setSoftwareProfile(?SoftwareProfile $softwareProfile): static
|
||||
{
|
||||
$this->softwareProfile = $softwareProfile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ class SoftwareProfile extends AbstractEntity
|
|||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?OrganizationalUnit $organizationalUnit = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var Collection<int, Software>
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Image;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Image>
|
||||
*/
|
||||
class ImageRepository extends AbstractRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Image::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?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\ImageInput;
|
||||
use App\Dto\Output\ImageOutput;
|
||||
use App\Repository\ImageRepository;
|
||||
|
||||
readonly class ImageProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ImageRepository $imageRepository,
|
||||
private ValidatorInterface $validator
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput
|
||||
{
|
||||
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 = []): ImageOutput
|
||||
{
|
||||
if (!($data instanceof ImageInput)) {
|
||||
throw new \Exception(sprintf('data is not instance of %s', ImageInput::class));
|
||||
}
|
||||
|
||||
$entity = null;
|
||||
if (isset($uriVariables['uuid'])) {
|
||||
$entity = $this->imageRepository->findOneByUuid($uriVariables['uuid']);
|
||||
}
|
||||
|
||||
$image = $data->createOrUpdateEntity($entity);
|
||||
$this->validator->validate($image);
|
||||
$this->imageRepository->save($image);
|
||||
|
||||
return new ImageOutput($image);
|
||||
}
|
||||
|
||||
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
|
||||
{
|
||||
$user = $this->imageRepository->findOneByUuid($uriVariables['uuid']);
|
||||
$this->imageRepository->delete($user);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -9,19 +9,16 @@ 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\HardwareProfileInput;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Dto\Output\HardwareOutput;
|
||||
use App\Dto\Output\HardwareProfileOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class HardwareProfileProvider implements ProviderInterface
|
||||
readonly class HardwareProfileProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProviderInterface $collectionProvider,
|
||||
private readonly ProviderInterface $itemProvider
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -9,17 +9,15 @@ 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\Output\ClientOutput;
|
||||
use App\Dto\Output\HardwareOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class HardwareProvider implements ProviderInterface
|
||||
readonly class HardwareProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProviderInterface $collectionProvider,
|
||||
private readonly ProviderInterface $itemProvider
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -9,22 +9,15 @@ 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\HardwareTypeInput;
|
||||
use App\Dto\Input\OperativeSystemInput;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Dto\Output\HardwareOutput;
|
||||
use App\Dto\Output\HardwareTypeOutput;
|
||||
use App\Dto\Output\NetworkSettingsOutput;
|
||||
use App\Dto\Output\OperativeSystemOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class HardwareTypeProvider implements ProviderInterface
|
||||
readonly class HardwareTypeProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProviderInterface $collectionProvider,
|
||||
private readonly ProviderInterface $itemProvider
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
<?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\ImageInput;
|
||||
use App\Dto\Output\ImageOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
readonly class ImageProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private ProviderInterface $collectionProvider,
|
||||
private 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 ImageOutput($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('Menu not found');
|
||||
}
|
||||
|
||||
return new ImageOutput($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 ImageInput($item) : null;
|
||||
}
|
||||
|
||||
return new ImageInput();
|
||||
}
|
||||
}
|
|
@ -9,11 +9,7 @@ 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\Output\ClientOutput;
|
||||
use App\Dto\Output\HardwareOutput;
|
||||
use App\Dto\Output\MenuOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
|
|
|
@ -9,20 +9,15 @@ 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\OperativeSystemInput;
|
||||
use App\Dto\Output\ClientOutput;
|
||||
use App\Dto\Output\HardwareOutput;
|
||||
use App\Dto\Output\NetworkSettingsOutput;
|
||||
use App\Dto\Output\OperativeSystemOutput;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class OperativeSystemProvider implements ProviderInterface
|
||||
readonly class OperativeSystemProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProviderInterface $collectionProvider,
|
||||
private readonly ProviderInterface $itemProvider
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -9,23 +9,16 @@ use ApiPlatform\Metadata\Patch;
|
|||
use ApiPlatform\Metadata\Put;
|
||||
use ApiPlatform\State\Pagination\TraversablePaginator;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\Dto\Input\OrganizationalUnitClassroomGroupInput;
|
||||
use App\Dto\Input\OrganizationalUnitClassroomInput;
|
||||
use App\Dto\Input\OrganizationalUnitClientGroupInput;
|
||||
use App\Dto\Input\OrganizationalUnitInput;
|
||||
use App\Dto\Input\OrganizationalUnitRootInput;
|
||||
use App\Dto\Input\PartitionInput;
|
||||
use App\Dto\Input\UserGroupInput;
|
||||
use App\Dto\Output\OrganizationalUnitOutput;
|
||||
use App\Entity\OrganizationalUnit;
|
||||
use App\Model\OrganizationalUnitTypes;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class OrganizationalUnitProvider implements ProviderInterface
|
||||
readonly class OrganizationalUnitProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProviderInterface $collectionProvider,
|
||||
private readonly ProviderInterface $itemProvider
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -9,21 +9,15 @@ 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
|
||||
readonly class PartitionProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ProviderInterface $collectionProvider,
|
||||
private readonly ProviderInterface $itemProvider
|
||||
private ProviderInterface $collectionProvider,
|
||||
private ProviderInterface $itemProvider
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue