refs #978. Image API updates

develop-jenkins
Manuel Aranda Rosales 2024-10-18 09:20:33 +02:00
parent ef3bda1322
commit a2171ceb47
8 changed files with 100 additions and 58 deletions

View File

@ -52,6 +52,18 @@ services:
$orderParameterName: 'order'
tags: [ 'api_platform.filter' ]
api_platform.filter.image.order:
parent: 'api_platform.doctrine.orm.order_filter'
arguments:
$properties: { 'id': ~, 'name': ~ }
$orderParameterName: 'order'
tags: [ 'api_platform.filter' ]
api_platform.filter.image.search:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'id': 'exact', 'name': 'partial', } ]
tags: [ 'api_platform.filter' ]
api_platform.filter.og_live.order:
parent: 'api_platform.doctrine.orm.order_filter'
arguments:

View File

@ -0,0 +1,39 @@
<?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 Version20241018055534 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 image DROP FOREIGN KEY FK_C53D045FFB84408A');
$this->addSql('ALTER TABLE image DROP FOREIGN KEY FK_C53D045F19EB6921');
$this->addSql('DROP INDEX IDX_C53D045F19EB6921 ON image');
$this->addSql('DROP INDEX IDX_C53D045FFB84408A ON image');
$this->addSql('ALTER TABLE image DROP client_id, DROP organizational_unit_id');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE image ADD client_id INT NOT NULL, ADD organizational_unit_id INT NOT NULL');
$this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045FFB84408A FOREIGN KEY (organizational_unit_id) REFERENCES organizational_unit (id)');
$this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (id)');
$this->addSql('CREATE INDEX IDX_C53D045F19EB6921 ON image (client_id)');
$this->addSql('CREATE INDEX IDX_C53D045FFB84408A ON image (organizational_unit_id)');
}
}

View File

@ -0,0 +1,31 @@
<?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 Version20241018060155 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 image ADD remote_pc TINYINT(1) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE image DROP remote_pc');
}
}

View File

@ -46,17 +46,12 @@ final class ImageInput
#[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;
#[Groups(['image:write'])]
#[ApiProperty(description: 'The organizational unit of the image')]
public ?OrganizationalUnitOutput $organizationalUnit = null;
public ?bool $remotePc = false;
public function __construct(?Image $image = null)
{
@ -72,18 +67,11 @@ final class ImageInput
$this->revision = $image->getRevision();
$this->info = $image->getInfo();
$this->size = $image->getSize();
if ($image->getClient()) {
$this->client = new ClientOutput($image->getClient());
}
$this->remotePc = $image->isRemotePc();
if ($image->getSoftwareProfile()) {
$this->softwareProfile = new SoftwareProfileOutput($image->getSoftwareProfile());
}
if ($image->getOrganizationalUnit()) {
$this->organizationalUnit = new OrganizationalUnitOutput($image->getOrganizationalUnit());
}
}
public function createOrUpdateEntity(?Image $image = null): Image
@ -100,14 +88,8 @@ final class ImageInput
$image->setRevision($this->revision);
$image->setInfo($this->info);
$image->setSize($this->size);
$image->setClient($this->client->getEntity());
$image->setSoftwareProfile($this->softwareProfile->getEntity());
if ($this->organizationalUnit) {
$image->setOrganizationalUnit($this->organizationalUnit->getEntity());
} else {
$image->setOrganizationalUnit($this->client->getEntity()->getOrganizationalUnit());
}
$image->setRemotePc($this->remotePc);
return $image;
}

View File

@ -34,13 +34,16 @@ final class ImageOutput extends AbstractOutput
public ?int $size = null;
#[Groups(['image:read'])]
public ?ClientOutput $clientOutput = null;
public ?bool $remotePc = null;
#[Groups(['image:read'])]
public ?SoftwareProfileOutput $softwareProfile = null;
#[Groups(['image:read'])]
public ?OrganizationalUnitOutput $organizationalUnit = null;
public \DateTime $createdAt;
#[Groups(['image:read'])]
public ?string $createdBy = null;
public function __construct(Image $image)
{
@ -54,8 +57,9 @@ final class ImageOutput extends AbstractOutput
$this->revision = $image->getRevision();
$this->info = $image->getInfo();
$this->size = $image->getSize();
$this->clientOutput = $image->getClient() ? new ClientOutput($image->getClient()) : null;
$this->softwareProfile = $image->getSoftwareProfile() ? new SoftwareProfileOutput($image->getSoftwareProfile()) : null;
$this->organizationalUnit = $image->getOrganizationalUnit() ? new OrganizationalUnitOutput($image->getOrganizationalUnit()) : null;
$this->remotePc = $image->isRemotePc();
$this->createdAt = $image->getCreatedAt();
$this->createdBy = $image->getCreatedBy();
}
}

View File

@ -33,10 +33,6 @@ class Image extends AbstractEntity
#[ORM\Column(length: 255, nullable: true)]
private ?int $size = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?Client $client = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
private ?SoftwareProfile $softwareProfile = null;
@ -47,9 +43,8 @@ class Image extends AbstractEntity
#[ORM\OneToMany(mappedBy: 'image', targetEntity: Partition::class)]
private Collection $partitions;
#[ORM\ManyToOne(inversedBy: 'images')]
#[ORM\JoinColumn(nullable: false)]
private ?OrganizationalUnit $organizationalUnit = null;
#[ORM\Column]
private ?bool $remotePc = null;
public function __construct()
{
@ -141,18 +136,6 @@ class Image extends AbstractEntity
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;
@ -195,14 +178,14 @@ class Image extends AbstractEntity
return $this;
}
public function getOrganizationalUnit(): ?OrganizationalUnit
public function isRemotePc(): ?bool
{
return $this->organizationalUnit;
return $this->remotePc;
}
public function setOrganizationalUnit(?OrganizationalUnit $organizationalUnit): static
public function setRemotePc(bool $remotePc): static
{
$this->organizationalUnit = $organizationalUnit;
$this->remotePc = $remotePc;
return $this;
}

View File

@ -33,14 +33,13 @@ final class ImageFactory extends ModelFactory
protected function getDefaults(): array
{
return [
'client' => ClientFactory::new(),
'createdAt' => self::faker()->dateTime(),
'name' => self::faker()->text(255),
'path' => self::faker()->text(255),
'size' => self::faker()->randomNumber(),
'softwareProfile' => SoftwareProfileFactory::new(),
'organizationalUnit' => OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT])->_save(),
'updatedAt' => self::faker()->dateTime(),
'remotePc' => self::faker()->boolean(),
];
}

View File

@ -64,22 +64,14 @@ class ImageTest extends AbstractTest
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
ClientFactory::createOne(['name' => self::CLIENT]);
$clientIri = $this->findIriBy(Client::class, ['name' => self::CLIENT]);
SoftwareProfileFactory::createOne(['description' => self::SOFTWARE_PROFILE]);
$swPIri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SOFTWARE_PROFILE]);
OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
$ouIri = $this->findIriBy(OrganizationalUnit::class, ['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
$this->createClientWithCredentials()->request('POST', '/images',['json' => [
'name' => self::IMAGE_CREATE,
'size' => 123,
'path' => '/path/to/image',
'client' => $clientIri,
'softwareProfile' => $swPIri,
'organizationalUnit' => $ouIri,
]]);
$this->assertResponseStatusCodeSame(201);