diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index d27362a..82f3fd0 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -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: diff --git a/migrations/Version20241018055534.php b/migrations/Version20241018055534.php new file mode 100644 index 0000000..0c1d5ab --- /dev/null +++ b/migrations/Version20241018055534.php @@ -0,0 +1,39 @@ +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)'); + } +} diff --git a/migrations/Version20241018060155.php b/migrations/Version20241018060155.php new file mode 100644 index 0000000..48d75fb --- /dev/null +++ b/migrations/Version20241018060155.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/src/Dto/Input/ImageInput.php b/src/Dto/Input/ImageInput.php index badbdc0..c1b2e84 100644 --- a/src/Dto/Input/ImageInput.php +++ b/src/Dto/Input/ImageInput.php @@ -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; } diff --git a/src/Dto/Output/ImageOutput.php b/src/Dto/Output/ImageOutput.php index 3f7df0c..fe91429 100644 --- a/src/Dto/Output/ImageOutput.php +++ b/src/Dto/Output/ImageOutput.php @@ -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(); } } \ No newline at end of file diff --git a/src/Entity/Image.php b/src/Entity/Image.php index bd25a0a..7dc8c05 100644 --- a/src/Entity/Image.php +++ b/src/Entity/Image.php @@ -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; } diff --git a/src/Factory/ImageFactory.php b/src/Factory/ImageFactory.php index 7e068af..52822df 100644 --- a/src/Factory/ImageFactory.php +++ b/src/Factory/ImageFactory.php @@ -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(), ]; } diff --git a/tests/Functional/ImageTest.php b/tests/Functional/ImageTest.php index 93eb45d..eee855f 100644 --- a/tests/Functional/ImageTest.php +++ b/tests/Functional/ImageTest.php @@ -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);