| @@ -5,6 +5,9 @@ | |||||
| ddev exec bin/console doctrine:migration:migrate | ddev exec bin/console doctrine:migration:migrate | ||||
| ddev exec bin/console doctrine:fixtures:load | ddev exec bin/console doctrine:fixtures:load | ||||
| ddev exec bin/console make:entity | ddev exec bin/console make:entity | ||||
| ddev exec bin/console make:factory | |||||
| ddev exec php bin/phpunit | |||||
| ddev exec php bin/phpunit --filter=testPostToCreateNewUserPost | |||||
| # Installation: | # Installation: | ||||
| @@ -1,35 +0,0 @@ | |||||
| <?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 Version20240321094704 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 document_object (id INT AUTO_INCREMENT NOT NULL, partner_id INT DEFAULT NULL, product_id INT DEFAULT NULL, file_path VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_16CF1A8A9393F8FE (partner_id), INDEX IDX_16CF1A8A4584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | |||||
| $this->addSql('ALTER TABLE document_object ADD CONSTRAINT FK_16CF1A8A9393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id)'); | |||||
| $this->addSql('ALTER TABLE document_object ADD CONSTRAINT FK_16CF1A8A4584665A FOREIGN KEY (product_id) REFERENCES product (id)'); | |||||
| } | |||||
| public function down(Schema $schema): void | |||||
| { | |||||
| // this down() migration is auto-generated, please modify it to your needs | |||||
| $this->addSql('ALTER TABLE document_object DROP FOREIGN KEY FK_16CF1A8A9393F8FE'); | |||||
| $this->addSql('ALTER TABLE document_object DROP FOREIGN KEY FK_16CF1A8A4584665A'); | |||||
| $this->addSql('DROP TABLE document_object'); | |||||
| } | |||||
| } | |||||
| @@ -1,35 +0,0 @@ | |||||
| <?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 Version20240322113223 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 partner_follow (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, partner_id INT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_55FFED0BA76ED395 (user_id), INDEX IDX_55FFED0B9393F8FE (partner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | |||||
| $this->addSql('ALTER TABLE partner_follow ADD CONSTRAINT FK_55FFED0BA76ED395 FOREIGN KEY (user_id) REFERENCES `user` (id) ON DELETE CASCADE'); | |||||
| $this->addSql('ALTER TABLE partner_follow ADD CONSTRAINT FK_55FFED0B9393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id) ON DELETE CASCADE'); | |||||
| } | |||||
| public function down(Schema $schema): void | |||||
| { | |||||
| // this down() migration is auto-generated, please modify it to your needs | |||||
| $this->addSql('ALTER TABLE partner_follow DROP FOREIGN KEY FK_55FFED0BA76ED395'); | |||||
| $this->addSql('ALTER TABLE partner_follow DROP FOREIGN KEY FK_55FFED0B9393F8FE'); | |||||
| $this->addSql('DROP TABLE partner_follow'); | |||||
| } | |||||
| } | |||||
| @@ -1,35 +0,0 @@ | |||||
| <?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 Version20240322155533 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 document_object ADD created_by_id INT NOT NULL, ADD name VARCHAR(255) NOT NULL, ADD description LONGTEXT DEFAULT NULL'); | |||||
| $this->addSql('ALTER TABLE document_object ADD CONSTRAINT FK_16CF1A8AB03A8386 FOREIGN KEY (created_by_id) REFERENCES `user` (id)'); | |||||
| $this->addSql('CREATE INDEX IDX_16CF1A8AB03A8386 ON document_object (created_by_id)'); | |||||
| } | |||||
| public function down(Schema $schema): void | |||||
| { | |||||
| // this down() migration is auto-generated, please modify it to your needs | |||||
| $this->addSql('ALTER TABLE document_object DROP FOREIGN KEY FK_16CF1A8AB03A8386'); | |||||
| $this->addSql('DROP INDEX IDX_16CF1A8AB03A8386 ON document_object'); | |||||
| $this->addSql('ALTER TABLE document_object DROP created_by_id, DROP name, DROP description'); | |||||
| } | |||||
| } | |||||
| @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; | |||||
| /** | /** | ||||
| * Auto-generated Migration: Please modify to your needs! | * Auto-generated Migration: Please modify to your needs! | ||||
| */ | */ | ||||
| final class Version20240320115901 extends AbstractMigration | |||||
| final class Version20240325145137 extends AbstractMigration | |||||
| { | { | ||||
| public function getDescription(): string | public function getDescription(): string | ||||
| { | { | ||||
| @@ -22,8 +22,11 @@ final class Version20240320115901 extends AbstractMigration | |||||
| // this up() migration is auto-generated, please modify it to your needs | // this up() migration is auto-generated, please modify it to your needs | ||||
| $this->addSql('CREATE TABLE comment (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, posting_id INT NOT NULL, message LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_9474526C7E3C61F9 (owner_id), INDEX IDX_9474526C9AE985F6 (posting_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | $this->addSql('CREATE TABLE comment (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, posting_id INT NOT NULL, message LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_9474526C7E3C61F9 (owner_id), INDEX IDX_9474526C9AE985F6 (posting_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||||
| $this->addSql('CREATE TABLE contact (id INT AUTO_INCREMENT NOT NULL, partner_id INT NOT NULL, image_id INT DEFAULT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, birthday DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', position VARCHAR(255) DEFAULT NULL, phone VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_4C62E6389393F8FE (partner_id), INDEX IDX_4C62E6383DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | $this->addSql('CREATE TABLE contact (id INT AUTO_INCREMENT NOT NULL, partner_id INT NOT NULL, image_id INT DEFAULT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, birthday DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', position VARCHAR(255) DEFAULT NULL, phone VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_4C62E6389393F8FE (partner_id), INDEX IDX_4C62E6383DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||||
| $this->addSql('CREATE TABLE document (id INT AUTO_INCREMENT NOT NULL, created_by_id INT NOT NULL, partner_id INT DEFAULT NULL, product_id INT DEFAULT NULL, document_object_id INT NOT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_D8698A76B03A8386 (created_by_id), INDEX IDX_D8698A769393F8FE (partner_id), INDEX IDX_D8698A764584665A (product_id), INDEX IDX_D8698A7631157E8A (document_object_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | |||||
| $this->addSql('CREATE TABLE document_object (id INT AUTO_INCREMENT NOT NULL, file_path VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | |||||
| $this->addSql('CREATE TABLE media_object (id INT AUTO_INCREMENT NOT NULL, file_path VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | $this->addSql('CREATE TABLE media_object (id INT AUTO_INCREMENT NOT NULL, file_path VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||||
| $this->addSql('CREATE TABLE partner (id INT AUTO_INCREMENT NOT NULL, logo_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, street VARCHAR(255) DEFAULT NULL, street_no VARCHAR(255) DEFAULT NULL, zip VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, country VARCHAR(255) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_312B3E16F98F144A (logo_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | $this->addSql('CREATE TABLE partner (id INT AUTO_INCREMENT NOT NULL, logo_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, street VARCHAR(255) DEFAULT NULL, street_no VARCHAR(255) DEFAULT NULL, zip VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, country VARCHAR(255) DEFAULT NULL, website VARCHAR(255) DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_312B3E16F98F144A (logo_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||||
| $this->addSql('CREATE TABLE partner_follow (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, partner_id INT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_55FFED0BA76ED395 (user_id), INDEX IDX_55FFED0B9393F8FE (partner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | |||||
| $this->addSql('CREATE TABLE posting (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, partner_id INT NOT NULL, contact_id INT DEFAULT NULL, sale_id INT DEFAULT NULL, headline VARCHAR(255) NOT NULL, message LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_BD275D737E3C61F9 (owner_id), INDEX IDX_BD275D739393F8FE (partner_id), INDEX IDX_BD275D73E7A1254A (contact_id), INDEX IDX_BD275D734A7E4868 (sale_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | $this->addSql('CREATE TABLE posting (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, partner_id INT NOT NULL, contact_id INT DEFAULT NULL, sale_id INT DEFAULT NULL, headline VARCHAR(255) NOT NULL, message LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_BD275D737E3C61F9 (owner_id), INDEX IDX_BD275D739393F8FE (partner_id), INDEX IDX_BD275D73E7A1254A (contact_id), INDEX IDX_BD275D734A7E4868 (sale_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||||
| $this->addSql('CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, image_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_D34A04AD3DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | $this->addSql('CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, image_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_D34A04AD3DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||||
| $this->addSql('CREATE TABLE sale (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, partner_id INT NOT NULL, product_id INT NOT NULL, turnover INT NOT NULL, profit INT DEFAULT NULL, comment LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_E54BC0057E3C61F9 (owner_id), INDEX IDX_E54BC0059393F8FE (partner_id), INDEX IDX_E54BC0054584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | $this->addSql('CREATE TABLE sale (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, partner_id INT NOT NULL, product_id INT NOT NULL, turnover INT NOT NULL, profit INT DEFAULT NULL, comment LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_E54BC0057E3C61F9 (owner_id), INDEX IDX_E54BC0059393F8FE (partner_id), INDEX IDX_E54BC0054584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||||
| @@ -34,7 +37,13 @@ final class Version20240320115901 extends AbstractMigration | |||||
| $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C9AE985F6 FOREIGN KEY (posting_id) REFERENCES posting (id) ON DELETE CASCADE'); | $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C9AE985F6 FOREIGN KEY (posting_id) REFERENCES posting (id) ON DELETE CASCADE'); | ||||
| $this->addSql('ALTER TABLE contact ADD CONSTRAINT FK_4C62E6389393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id) ON DELETE CASCADE'); | $this->addSql('ALTER TABLE contact ADD CONSTRAINT FK_4C62E6389393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id) ON DELETE CASCADE'); | ||||
| $this->addSql('ALTER TABLE contact ADD CONSTRAINT FK_4C62E6383DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL'); | $this->addSql('ALTER TABLE contact ADD CONSTRAINT FK_4C62E6383DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL'); | ||||
| $this->addSql('ALTER TABLE document ADD CONSTRAINT FK_D8698A76B03A8386 FOREIGN KEY (created_by_id) REFERENCES `user` (id)'); | |||||
| $this->addSql('ALTER TABLE document ADD CONSTRAINT FK_D8698A769393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id)'); | |||||
| $this->addSql('ALTER TABLE document ADD CONSTRAINT FK_D8698A764584665A FOREIGN KEY (product_id) REFERENCES product (id)'); | |||||
| $this->addSql('ALTER TABLE document ADD CONSTRAINT FK_D8698A7631157E8A FOREIGN KEY (document_object_id) REFERENCES document_object (id)'); | |||||
| $this->addSql('ALTER TABLE partner ADD CONSTRAINT FK_312B3E16F98F144A FOREIGN KEY (logo_id) REFERENCES media_object (id) ON DELETE SET NULL'); | $this->addSql('ALTER TABLE partner ADD CONSTRAINT FK_312B3E16F98F144A FOREIGN KEY (logo_id) REFERENCES media_object (id) ON DELETE SET NULL'); | ||||
| $this->addSql('ALTER TABLE partner_follow ADD CONSTRAINT FK_55FFED0BA76ED395 FOREIGN KEY (user_id) REFERENCES `user` (id) ON DELETE CASCADE'); | |||||
| $this->addSql('ALTER TABLE partner_follow ADD CONSTRAINT FK_55FFED0B9393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id) ON DELETE CASCADE'); | |||||
| $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D737E3C61F9 FOREIGN KEY (owner_id) REFERENCES `user` (id) ON DELETE CASCADE'); | $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D737E3C61F9 FOREIGN KEY (owner_id) REFERENCES `user` (id) ON DELETE CASCADE'); | ||||
| $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D739393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id) ON DELETE CASCADE'); | $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D739393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id) ON DELETE CASCADE'); | ||||
| $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D73E7A1254A FOREIGN KEY (contact_id) REFERENCES contact (id) ON DELETE CASCADE'); | $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D73E7A1254A FOREIGN KEY (contact_id) REFERENCES contact (id) ON DELETE CASCADE'); | ||||
| @@ -59,7 +68,13 @@ final class Version20240320115901 extends AbstractMigration | |||||
| $this->addSql('ALTER TABLE comment DROP FOREIGN KEY FK_9474526C9AE985F6'); | $this->addSql('ALTER TABLE comment DROP FOREIGN KEY FK_9474526C9AE985F6'); | ||||
| $this->addSql('ALTER TABLE contact DROP FOREIGN KEY FK_4C62E6389393F8FE'); | $this->addSql('ALTER TABLE contact DROP FOREIGN KEY FK_4C62E6389393F8FE'); | ||||
| $this->addSql('ALTER TABLE contact DROP FOREIGN KEY FK_4C62E6383DA5256D'); | $this->addSql('ALTER TABLE contact DROP FOREIGN KEY FK_4C62E6383DA5256D'); | ||||
| $this->addSql('ALTER TABLE document DROP FOREIGN KEY FK_D8698A76B03A8386'); | |||||
| $this->addSql('ALTER TABLE document DROP FOREIGN KEY FK_D8698A769393F8FE'); | |||||
| $this->addSql('ALTER TABLE document DROP FOREIGN KEY FK_D8698A764584665A'); | |||||
| $this->addSql('ALTER TABLE document DROP FOREIGN KEY FK_D8698A7631157E8A'); | |||||
| $this->addSql('ALTER TABLE partner DROP FOREIGN KEY FK_312B3E16F98F144A'); | $this->addSql('ALTER TABLE partner DROP FOREIGN KEY FK_312B3E16F98F144A'); | ||||
| $this->addSql('ALTER TABLE partner_follow DROP FOREIGN KEY FK_55FFED0BA76ED395'); | |||||
| $this->addSql('ALTER TABLE partner_follow DROP FOREIGN KEY FK_55FFED0B9393F8FE'); | |||||
| $this->addSql('ALTER TABLE posting DROP FOREIGN KEY FK_BD275D737E3C61F9'); | $this->addSql('ALTER TABLE posting DROP FOREIGN KEY FK_BD275D737E3C61F9'); | ||||
| $this->addSql('ALTER TABLE posting DROP FOREIGN KEY FK_BD275D739393F8FE'); | $this->addSql('ALTER TABLE posting DROP FOREIGN KEY FK_BD275D739393F8FE'); | ||||
| $this->addSql('ALTER TABLE posting DROP FOREIGN KEY FK_BD275D73E7A1254A'); | $this->addSql('ALTER TABLE posting DROP FOREIGN KEY FK_BD275D73E7A1254A'); | ||||
| @@ -77,8 +92,11 @@ final class Version20240320115901 extends AbstractMigration | |||||
| $this->addSql('ALTER TABLE `user` DROP FOREIGN KEY FK_8D93D6493DA5256D'); | $this->addSql('ALTER TABLE `user` DROP FOREIGN KEY FK_8D93D6493DA5256D'); | ||||
| $this->addSql('DROP TABLE comment'); | $this->addSql('DROP TABLE comment'); | ||||
| $this->addSql('DROP TABLE contact'); | $this->addSql('DROP TABLE contact'); | ||||
| $this->addSql('DROP TABLE document'); | |||||
| $this->addSql('DROP TABLE document_object'); | |||||
| $this->addSql('DROP TABLE media_object'); | $this->addSql('DROP TABLE media_object'); | ||||
| $this->addSql('DROP TABLE partner'); | $this->addSql('DROP TABLE partner'); | ||||
| $this->addSql('DROP TABLE partner_follow'); | |||||
| $this->addSql('DROP TABLE posting'); | $this->addSql('DROP TABLE posting'); | ||||
| $this->addSql('DROP TABLE product'); | $this->addSql('DROP TABLE product'); | ||||
| $this->addSql('DROP TABLE sale'); | $this->addSql('DROP TABLE sale'); | ||||
| @@ -0,0 +1,87 @@ | |||||
| <?php | |||||
| /** | |||||
| * @author Daniel Knudsen <d.knudsen@spawntree.de> | |||||
| * @date 12.12.23 | |||||
| */ | |||||
| namespace App\ApiResource; | |||||
| use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; | |||||
| use ApiPlatform\Doctrine\Orm\State\Options; | |||||
| use ApiPlatform\Metadata\ApiFilter; | |||||
| use ApiPlatform\Metadata\ApiProperty; | |||||
| use ApiPlatform\Metadata\ApiResource; | |||||
| use App\Entity\Comment; | |||||
| use App\Entity\Document; | |||||
| use App\Entity\DocumentObject; | |||||
| use App\Entity\Partner; | |||||
| use App\Interface\OwnerInterface; | |||||
| use App\State\EntityClassDtoStateProcessor; | |||||
| use App\State\EntityToDtoStateProvider; | |||||
| use ApiPlatform\Metadata\Delete; | |||||
| use ApiPlatform\Metadata\Get; | |||||
| use ApiPlatform\Metadata\GetCollection; | |||||
| use ApiPlatform\Metadata\Patch; | |||||
| use ApiPlatform\Metadata\Post; | |||||
| use App\Validator\IsValidOwner; | |||||
| use Symfony\Component\Serializer\Attribute\Groups; | |||||
| use Symfony\Component\Validator\Constraints\NotBlank; | |||||
| #[ApiResource( | |||||
| shortName: 'Document', | |||||
| operations: [ | |||||
| new Get( | |||||
| security: 'is_granted("ROLE_USER")' | |||||
| ), | |||||
| new GetCollection( | |||||
| security: 'is_granted("ROLE_USER")', | |||||
| ), | |||||
| new Post( | |||||
| security: 'is_granted("ROLE_USER")', | |||||
| ), | |||||
| new Patch( | |||||
| security: 'is_granted("ROLE_USER")', | |||||
| ), | |||||
| new Delete( | |||||
| security: 'is_granted("ROLE_ADMIN")', | |||||
| ) | |||||
| ], | |||||
| security: 'is_granted("ROLE_USER")', | |||||
| provider: EntityToDtoStateProvider::class, | |||||
| processor: EntityClassDtoStateProcessor::class, | |||||
| stateOptions: new Options(entityClass: Document::class), | |||||
| )] | |||||
| #[ApiFilter(SearchFilter::class, properties: ['owner' => 'exact', 'partner' => 'exact', 'product' => 'exact'])] | |||||
| class DocumentApi | |||||
| { | |||||
| #[ApiProperty(readable: false, writable: false, identifier: true)] | |||||
| public ?int $id = null; | |||||
| #[ApiProperty(writable: false)] | |||||
| public ?UserApi $createdBy = null; | |||||
| #[ApiProperty(writable: false)] | |||||
| public ?string $createdByName = null; | |||||
| #[NotBlank] | |||||
| public ?string $name = null; | |||||
| public ?string $description = null; | |||||
| public ?PartnerApi $partner = null; | |||||
| #[ApiProperty(writable: false)] | |||||
| public ?string $partnerName = null; | |||||
| public ?ProductApi $product = null; | |||||
| #[ApiProperty(writable: false)] | |||||
| public ?string $productName = null; | |||||
| #[NotBlank] | |||||
| public ?DocumentObject $documentObject = null; | |||||
| #[ApiProperty(writable: false)] | |||||
| public ?\DateTimeImmutable $createdAt = null; | |||||
| } | |||||
| @@ -8,52 +8,25 @@ | |||||
| namespace App\Controller; | namespace App\Controller; | ||||
| use ApiPlatform\Api\IriConverterInterface; | |||||
| use App\Entity\DocumentObject; | use App\Entity\DocumentObject; | ||||
| use App\Entity\Partner; | |||||
| use App\Entity\Product; | |||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpKernel\Attribute\AsController; | use Symfony\Component\HttpKernel\Attribute\AsController; | ||||
| use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | ||||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | |||||
| #[AsController] | #[AsController] | ||||
| final class CreateDocumentObjectAction extends AbstractController | final class CreateDocumentObjectAction extends AbstractController | ||||
| { | { | ||||
| public function __invoke( | |||||
| Request $request, | |||||
| IriConverterInterface $iriConverter, | |||||
| MicroMapperInterface $microMapper | |||||
| ): DocumentObject { | |||||
| public function __invoke(Request $request): DocumentObject | |||||
| { | |||||
| $uploadedFile = $request->files->get('file'); | $uploadedFile = $request->files->get('file'); | ||||
| if (!$uploadedFile) { | if (!$uploadedFile) { | ||||
| throw new BadRequestHttpException('"file" is required'); | throw new BadRequestHttpException('"file" is required'); | ||||
| } | } | ||||
| $documentObject = new DocumentObject(); | |||||
| $documentObject->file = $uploadedFile; | |||||
| $mediaObject = new DocumentObject(); | |||||
| $mediaObject->file = $uploadedFile; | |||||
| $partnerIri = $request->request->get('partner'); | |||||
| if ($partnerIri !== null) { | |||||
| try { | |||||
| $partnerApi = $iriConverter->getResourceFromIri($partnerIri); | |||||
| } catch (\Exception $exception) { | |||||
| throw new BadRequestHttpException('invalid partner iri'); | |||||
| } | |||||
| $documentObject->setPartner($microMapper->map($partnerApi, Partner::class)); | |||||
| } | |||||
| $productIri = $request->request->get('product'); | |||||
| if ($productIri !== null) { | |||||
| try { | |||||
| $productApi = $iriConverter->getResourceFromIri($productIri); | |||||
| } catch (\Exception $exception) { | |||||
| throw new BadRequestHttpException('invalid product iri'); | |||||
| } | |||||
| $documentObject->setProduct($microMapper->map($productApi, Product::class)); | |||||
| } | |||||
| return $documentObject; | |||||
| return $mediaObject; | |||||
| } | } | ||||
| } | } | ||||
| @@ -2,8 +2,10 @@ | |||||
| namespace App\DataFixtures; | namespace App\DataFixtures; | ||||
| use App\Entity\Document; | |||||
| use App\Factory\CommentFactory; | use App\Factory\CommentFactory; | ||||
| use App\Factory\ContactFactory; | use App\Factory\ContactFactory; | ||||
| use App\Factory\DocumentFactory; | |||||
| use App\Factory\DocumentObjectFactory; | use App\Factory\DocumentObjectFactory; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectProductFactory; | use App\Factory\MediaObjectProductFactory; | ||||
| @@ -75,7 +77,8 @@ class AppFixtures extends Fixture | |||||
| MediaObjectProductFactory::createMany(50); | MediaObjectProductFactory::createMany(50); | ||||
| TaskFactory::createMany(50); | TaskFactory::createMany(50); | ||||
| TaskNoteFactory::createMany(100); | TaskNoteFactory::createMany(100); | ||||
| DocumentObjectFactory::createMany(50); | |||||
| PartnerFollowFactory::createMany(100); | PartnerFollowFactory::createMany(100); | ||||
| DocumentObjectFactory::createMany(50); | |||||
| DocumentFactory::createMany(50); | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,119 @@ | |||||
| <?php | |||||
| /** | |||||
| * @author Daniel Knudsen <d.knudsen@spawntree.de> | |||||
| * @date 25.01.24 | |||||
| */ | |||||
| namespace App\Entity; | |||||
| use ApiPlatform\Metadata\ApiProperty; | |||||
| use Doctrine\DBAL\Types\Types; | |||||
| use Doctrine\ORM\Mapping as ORM; | |||||
| #[ORM\Entity] | |||||
| class Document | |||||
| { | |||||
| #[ORM\Id, ORM\Column, ORM\GeneratedValue] | |||||
| private ?int $id = null; | |||||
| #[ORM\ManyToOne(inversedBy: 'documents')] | |||||
| #[ORM\JoinColumn(nullable: false)] | |||||
| private ?User $createdBy = null; | |||||
| #[ORM\Column(length: 255)] | |||||
| private ?string $name = null; | |||||
| #[ORM\Column(type: Types::TEXT, nullable: true)] | |||||
| private ?string $description = null; | |||||
| #[ORM\ManyToOne(inversedBy: 'documents')] | |||||
| private ?Partner $partner = null; | |||||
| #[ORM\ManyToOne(inversedBy: 'documents')] | |||||
| private ?Product $product = null; | |||||
| #[ORM\ManyToOne] | |||||
| #[ORM\JoinColumn(nullable: false)] | |||||
| private ?DocumentObject $documentObject = null; | |||||
| #[ApiProperty(writable: false)] | |||||
| #[ORM\Column] | |||||
| private ?\DateTimeImmutable $createdAt = null; | |||||
| public function __construct(User $createdBy, DocumentObject $documentObject) | |||||
| { | |||||
| $this->createdBy = $createdBy; | |||||
| $this->documentObject = $documentObject; | |||||
| $this->createdAt = new \DateTimeImmutable(); | |||||
| } | |||||
| public function getId(): ?int | |||||
| { | |||||
| return $this->id; | |||||
| } | |||||
| public function getCreatedBy(): ?User | |||||
| { | |||||
| return $this->createdBy; | |||||
| } | |||||
| public function setCreatedBy(?User $createdBy): void | |||||
| { | |||||
| $this->createdBy = $createdBy; | |||||
| } | |||||
| public function getName(): ?string | |||||
| { | |||||
| return $this->name; | |||||
| } | |||||
| public function setName(?string $name): void | |||||
| { | |||||
| $this->name = $name; | |||||
| } | |||||
| public function getDescription(): ?string | |||||
| { | |||||
| return $this->description; | |||||
| } | |||||
| public function setDescription(?string $description): void | |||||
| { | |||||
| $this->description = $description; | |||||
| } | |||||
| public function getPartner(): ?Partner | |||||
| { | |||||
| return $this->partner; | |||||
| } | |||||
| public function setPartner(?Partner $partner): void | |||||
| { | |||||
| $this->partner = $partner; | |||||
| } | |||||
| public function getProduct(): ?Product | |||||
| { | |||||
| return $this->product; | |||||
| } | |||||
| public function setProduct(?Product $product): void | |||||
| { | |||||
| $this->product = $product; | |||||
| } | |||||
| public function getDocumentObject(): ?DocumentObject | |||||
| { | |||||
| return $this->documentObject; | |||||
| } | |||||
| public function setDocumentObject(?DocumentObject $documentObject): void | |||||
| { | |||||
| $this->documentObject = $documentObject; | |||||
| } | |||||
| public function getCreatedAt(): ?\DateTimeImmutable | |||||
| { | |||||
| return $this->createdAt; | |||||
| } | |||||
| } | |||||
| @@ -4,10 +4,9 @@ | |||||
| * @date 25.01.24 | * @date 25.01.24 | ||||
| */ | */ | ||||
| namespace App\Entity; | namespace App\Entity; | ||||
| use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; | |||||
| use ApiPlatform\Metadata\ApiFilter; | |||||
| use ApiPlatform\Metadata\ApiProperty; | use ApiPlatform\Metadata\ApiProperty; | ||||
| use ApiPlatform\Metadata\ApiResource; | use ApiPlatform\Metadata\ApiResource; | ||||
| use ApiPlatform\Metadata\Delete; | use ApiPlatform\Metadata\Delete; | ||||
| @@ -16,7 +15,6 @@ use ApiPlatform\Metadata\GetCollection; | |||||
| use ApiPlatform\Metadata\Post; | use ApiPlatform\Metadata\Post; | ||||
| use ApiPlatform\OpenApi\Model; | use ApiPlatform\OpenApi\Model; | ||||
| use App\Controller\CreateDocumentObjectAction; | use App\Controller\CreateDocumentObjectAction; | ||||
| use Doctrine\DBAL\Types\Types; | |||||
| use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
| use Symfony\Component\HttpFoundation\File\File; | use Symfony\Component\HttpFoundation\File\File; | ||||
| use Symfony\Component\Serializer\Annotation\Groups; | use Symfony\Component\Serializer\Annotation\Groups; | ||||
| @@ -26,7 +24,7 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich; | |||||
| #[Vich\Uploadable] | #[Vich\Uploadable] | ||||
| #[ORM\Entity] | #[ORM\Entity] | ||||
| #[ApiResource( | #[ApiResource( | ||||
| shortName: 'Document', | |||||
| shortName: 'DocumentObject', | |||||
| types: ['https://schema.org/MediaObject'], | types: ['https://schema.org/MediaObject'], | ||||
| operations: [ | operations: [ | ||||
| new Get(), | new Get(), | ||||
| @@ -40,72 +38,29 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich; | |||||
| 'schema' => [ | 'schema' => [ | ||||
| 'type' => 'object', | 'type' => 'object', | ||||
| 'properties' => [ | 'properties' => [ | ||||
| 'name' => [ | |||||
| 'type' => 'string', | |||||
| 'required' => true, | |||||
| ], | |||||
| 'description' => [ | |||||
| 'type' => 'text', | |||||
| 'required' => true, | |||||
| ], | |||||
| 'file' => [ | 'file' => [ | ||||
| 'type' => 'string', | 'type' => 'string', | ||||
| 'format' => 'binary' | 'format' => 'binary' | ||||
| ], | |||||
| 'partner' => [ | |||||
| 'type' => 'string', | |||||
| 'format' => 'iri_reference', | |||||
| 'example' => 'https://example.com/' | |||||
| ], | |||||
| 'product' => [ | |||||
| 'type' => 'string', | |||||
| 'format' => 'iri_reference', | |||||
| 'example' => 'https://example.com/' | |||||
| ] | ] | ||||
| ], | |||||
| ], | |||||
| ], | |||||
| ] | |||||
| ] | |||||
| ] | |||||
| ]) | ]) | ||||
| ) | ) | ||||
| ), | ), | ||||
| validationContext: ['groups' => ['Default', 'document_object:create']], | validationContext: ['groups' => ['Default', 'document_object:create']], | ||||
| deserialize: false | deserialize: false | ||||
| ), | ), | ||||
| new Delete( | |||||
| // controller: DeleteMediaObjectAction::class | |||||
| ), | |||||
| new Delete(), | |||||
| ], | ], | ||||
| normalizationContext: ['groups' => ['document_object:read']], | normalizationContext: ['groups' => ['document_object:read']], | ||||
| security: 'is_granted("ROLE_USER")', | security: 'is_granted("ROLE_USER")', | ||||
| )] | )] | ||||
| #[ApiFilter(SearchFilter::class, properties: ['partner' => 'exact', 'product' => 'exact'])] | |||||
| class DocumentObject | class DocumentObject | ||||
| { | { | ||||
| #[ORM\Id, ORM\Column, ORM\GeneratedValue] | #[ORM\Id, ORM\Column, ORM\GeneratedValue] | ||||
| private ?int $id = null; | private ?int $id = null; | ||||
| #[Groups(['document_object:read', 'document_object:create'])] | |||||
| #[ORM\ManyToOne(inversedBy: 'documentObjects')] | |||||
| #[ORM\JoinColumn(nullable: false)] | |||||
| private ?User $createdBy = null; | |||||
| #[Groups(['document_object:read', 'document_object:create'])] | |||||
| #[Assert\NotNull(groups: ['document_object:create'])] | |||||
| #[ORM\Column(length: 255)] | |||||
| private ?string $name = null; | |||||
| #[Groups(['document_object:read', 'document_object:create'])] | |||||
| #[ORM\Column(type: Types::TEXT, nullable: true)] | |||||
| private ?string $description = null; | |||||
| #[Groups(['document_object:read', 'document_object:create'])] | |||||
| #[ORM\ManyToOne(inversedBy: 'documentObjects')] | |||||
| private ?Partner $partner = null; | |||||
| #[Groups(['document_object:read', 'document_object:create'])] | |||||
| #[ORM\ManyToOne(inversedBy: 'documentObjects')] | |||||
| private ?Product $product = null; | |||||
| #[ApiProperty(types: ['https://schema.org/contentUrl'])] | #[ApiProperty(types: ['https://schema.org/contentUrl'])] | ||||
| #[Groups(['document_object:read'])] | #[Groups(['document_object:read'])] | ||||
| public ?string $contentUrl = null; | public ?string $contentUrl = null; | ||||
| @@ -117,8 +72,6 @@ class DocumentObject | |||||
| #[ORM\Column(nullable: true)] | #[ORM\Column(nullable: true)] | ||||
| public ?string $filePath = null; | public ?string $filePath = null; | ||||
| #[ApiProperty(writable: false)] | |||||
| #[Groups(['document_object:read'])] | |||||
| #[ORM\Column] | #[ORM\Column] | ||||
| private ?\DateTimeImmutable $createdAt = null; | private ?\DateTimeImmutable $createdAt = null; | ||||
| @@ -152,64 +105,4 @@ class DocumentObject | |||||
| return $this->createdAt; | return $this->createdAt; | ||||
| } | } | ||||
| public function getPartner(): ?Partner | |||||
| { | |||||
| return $this->partner; | |||||
| } | |||||
| public function setPartner(?Partner $partner): static | |||||
| { | |||||
| $this->partner = $partner; | |||||
| return $this; | |||||
| } | |||||
| public function getProduct(): ?Product | |||||
| { | |||||
| return $this->product; | |||||
| } | |||||
| public function setProduct(?Product $product): static | |||||
| { | |||||
| $this->product = $product; | |||||
| return $this; | |||||
| } | |||||
| public function getCreatedBy(): ?User | |||||
| { | |||||
| return $this->createdBy; | |||||
| } | |||||
| public function setCreatedBy(?User $createdBy): static | |||||
| { | |||||
| $this->createdBy = $createdBy; | |||||
| return $this; | |||||
| } | |||||
| public function getName(): ?string | |||||
| { | |||||
| return $this->name; | |||||
| } | |||||
| public function setName(string $name): static | |||||
| { | |||||
| $this->name = $name; | |||||
| return $this; | |||||
| } | |||||
| public function getDescription(): ?string | |||||
| { | |||||
| return $this->description; | |||||
| } | |||||
| public function setDescription(?string $description): static | |||||
| { | |||||
| $this->description = $description; | |||||
| return $this; | |||||
| } | |||||
| } | } | ||||
| @@ -24,7 +24,7 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich; | |||||
| #[Vich\Uploadable] | #[Vich\Uploadable] | ||||
| #[ORM\Entity] | #[ORM\Entity] | ||||
| #[ApiResource( | #[ApiResource( | ||||
| shortName: 'Media', | |||||
| shortName: 'MediaObject', | |||||
| types: ['https://schema.org/MediaObject'], | types: ['https://schema.org/MediaObject'], | ||||
| operations: [ | operations: [ | ||||
| new Get(), | new Get(), | ||||
| @@ -51,9 +51,7 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich; | |||||
| validationContext: ['groups' => ['Default', 'media_object:create']], | validationContext: ['groups' => ['Default', 'media_object:create']], | ||||
| deserialize: false | deserialize: false | ||||
| ), | ), | ||||
| new Delete( | |||||
| // controller: DeleteMediaObjectAction::class | |||||
| ), | |||||
| new Delete(), | |||||
| ], | ], | ||||
| normalizationContext: ['groups' => ['media_object:read']], | normalizationContext: ['groups' => ['media_object:read']], | ||||
| security: 'is_granted("ROLE_USER")', | security: 'is_granted("ROLE_USER")', | ||||
| @@ -57,7 +57,7 @@ class Partner | |||||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Sale::class)] | #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Sale::class)] | ||||
| private Collection $sales; | private Collection $sales; | ||||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: DocumentObject::class)] | |||||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Document::class)] | |||||
| private Collection $documentObjects; | private Collection $documentObjects; | ||||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: PartnerFollow::class)] | #[ORM\OneToMany(mappedBy: 'partner', targetEntity: PartnerFollow::class)] | ||||
| @@ -249,14 +249,14 @@ class Partner | |||||
| } | } | ||||
| /** | /** | ||||
| * @return Collection<int, DocumentObject> | |||||
| * @return Collection<int, Document> | |||||
| */ | */ | ||||
| public function getDocumentObjects(): Collection | public function getDocumentObjects(): Collection | ||||
| { | { | ||||
| return $this->documentObjects; | return $this->documentObjects; | ||||
| } | } | ||||
| public function addDocumentObject(DocumentObject $documentObject): static | |||||
| public function addDocumentObject(Document $documentObject): static | |||||
| { | { | ||||
| if (!$this->documentObjects->contains($documentObject)) { | if (!$this->documentObjects->contains($documentObject)) { | ||||
| $this->documentObjects->add($documentObject); | $this->documentObjects->add($documentObject); | ||||
| @@ -266,7 +266,7 @@ class Partner | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function removeDocumentObject(DocumentObject $documentObject): static | |||||
| public function removeDocumentObject(Document $documentObject): static | |||||
| { | { | ||||
| if ($this->documentObjects->removeElement($documentObject)) { | if ($this->documentObjects->removeElement($documentObject)) { | ||||
| // set the owning side to null (unless already changed) | // set the owning side to null (unless already changed) | ||||
| @@ -32,7 +32,7 @@ class Product | |||||
| #[ORM\OneToMany(mappedBy: 'product', targetEntity: Sale::class)] | #[ORM\OneToMany(mappedBy: 'product', targetEntity: Sale::class)] | ||||
| private Collection $sales; | private Collection $sales; | ||||
| #[ORM\OneToMany(mappedBy: 'product', targetEntity: DocumentObject::class)] | |||||
| #[ORM\OneToMany(mappedBy: 'product', targetEntity: Document::class)] | |||||
| private Collection $documentObjects; | private Collection $documentObjects; | ||||
| public function __construct() | public function __construct() | ||||
| @@ -119,14 +119,14 @@ class Product | |||||
| } | } | ||||
| /** | /** | ||||
| * @return Collection<int, DocumentObject> | |||||
| * @return Collection<int, Document> | |||||
| */ | */ | ||||
| public function getDocumentObjects(): Collection | public function getDocumentObjects(): Collection | ||||
| { | { | ||||
| return $this->documentObjects; | return $this->documentObjects; | ||||
| } | } | ||||
| public function addDocumentObject(DocumentObject $documentObject): static | |||||
| public function addDocumentObject(Document $documentObject): static | |||||
| { | { | ||||
| if (!$this->documentObjects->contains($documentObject)) { | if (!$this->documentObjects->contains($documentObject)) { | ||||
| $this->documentObjects->add($documentObject); | $this->documentObjects->add($documentObject); | ||||
| @@ -136,7 +136,7 @@ class Product | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function removeDocumentObject(DocumentObject $documentObject): static | |||||
| public function removeDocumentObject(Document $documentObject): static | |||||
| { | { | ||||
| if ($this->documentObjects->removeElement($documentObject)) { | if ($this->documentObjects->removeElement($documentObject)) { | ||||
| // set the owning side to null (unless already changed) | // set the owning side to null (unless already changed) | ||||
| @@ -58,7 +58,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface | |||||
| #[ORM\OneToMany(mappedBy: 'user', targetEntity: PartnerFollow::class)] | #[ORM\OneToMany(mappedBy: 'user', targetEntity: PartnerFollow::class)] | ||||
| private Collection $partnerFollows; | private Collection $partnerFollows; | ||||
| #[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: DocumentObject::class)] | |||||
| #[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Document::class)] | |||||
| private Collection $documentObjects; | private Collection $documentObjects; | ||||
| @@ -320,14 +320,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface | |||||
| } | } | ||||
| /** | /** | ||||
| * @return Collection<int, DocumentObject> | |||||
| * @return Collection<int, Document> | |||||
| */ | */ | ||||
| public function getDocumentObjects(): Collection | public function getDocumentObjects(): Collection | ||||
| { | { | ||||
| return $this->documentObjects; | return $this->documentObjects; | ||||
| } | } | ||||
| public function addDocumentObject(DocumentObject $documentObject): static | |||||
| public function addDocumentObject(Document $documentObject): static | |||||
| { | { | ||||
| if (!$this->documentObjects->contains($documentObject)) { | if (!$this->documentObjects->contains($documentObject)) { | ||||
| $this->documentObjects->add($documentObject); | $this->documentObjects->add($documentObject); | ||||
| @@ -337,7 +337,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function removeDocumentObject(DocumentObject $documentObject): static | |||||
| public function removeDocumentObject(Document $documentObject): static | |||||
| { | { | ||||
| if ($this->documentObjects->removeElement($documentObject)) { | if ($this->documentObjects->removeElement($documentObject)) { | ||||
| // set the owning side to null (unless already changed) | // set the owning side to null (unless already changed) | ||||
| @@ -0,0 +1,75 @@ | |||||
| <?php | |||||
| namespace App\Factory; | |||||
| use App\DataFixtures\FakeValues; | |||||
| use App\Entity\Document; | |||||
| use Doctrine\ORM\EntityRepository; | |||||
| use Zenstruck\Foundry\ModelFactory; | |||||
| use Zenstruck\Foundry\Proxy; | |||||
| use Zenstruck\Foundry\RepositoryProxy; | |||||
| /** | |||||
| * @extends ModelFactory<Document> | |||||
| * | |||||
| * @method Document|Proxy create(array|callable $attributes = []) | |||||
| * @method static Document|Proxy createOne(array $attributes = []) | |||||
| * @method static Document|Proxy find(object|array|mixed $criteria) | |||||
| * @method static Document|Proxy findOrCreate(array $attributes) | |||||
| * @method static Document|Proxy first(string $sortedField = 'id') | |||||
| * @method static Document|Proxy last(string $sortedField = 'id') | |||||
| * @method static Document|Proxy random(array $attributes = []) | |||||
| * @method static Document|Proxy randomOrCreate(array $attributes = []) | |||||
| * @method static EntityRepository|RepositoryProxy repository() | |||||
| * @method static Document[]|Proxy[] all() | |||||
| * @method static Document[]|Proxy[] createMany(int $number, array|callable $attributes = []) | |||||
| * @method static Document[]|Proxy[] createSequence(iterable|callable $sequence) | |||||
| * @method static Document[]|Proxy[] findBy(array $attributes) | |||||
| * @method static Document[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) | |||||
| * @method static Document[]|Proxy[] randomSet(int $number, array $attributes = []) | |||||
| */ | |||||
| final class DocumentFactory extends ModelFactory | |||||
| { | |||||
| /** | |||||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services | |||||
| * | |||||
| * @todo inject services if required | |||||
| */ | |||||
| public function __construct() | |||||
| { | |||||
| parent::__construct(); | |||||
| } | |||||
| /** | |||||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories | |||||
| * | |||||
| * @todo add your default values here | |||||
| */ | |||||
| protected function getDefaults(): array | |||||
| { | |||||
| $randBool = (bool)random_int(0, 1); | |||||
| return [ | |||||
| 'createdBy' => UserFactory::random(), | |||||
| 'documentObject' => DocumentObjectFactory::random(), | |||||
| 'name' => self::faker()->randomElement(FakeValues::BUSINESS_FILE_NAMES), | |||||
| 'description' => self::faker()->text(), | |||||
| 'partner' => $randBool ? PartnerFactory::random() : null, | |||||
| 'product' => !$randBool ? ProductFactory::random() : null, | |||||
| ]; | |||||
| } | |||||
| /** | |||||
| * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization | |||||
| */ | |||||
| protected function initialize(): self | |||||
| { | |||||
| return $this | |||||
| // ->afterInstantiate(function(Document $document): void {}) | |||||
| ; | |||||
| } | |||||
| protected static function getClass(): string | |||||
| { | |||||
| return Document::class; | |||||
| } | |||||
| } | |||||
| @@ -2,7 +2,6 @@ | |||||
| namespace App\Factory; | namespace App\Factory; | ||||
| use App\DataFixtures\FakeValues; | |||||
| use App\Entity\DocumentObject; | use App\Entity\DocumentObject; | ||||
| use Doctrine\ORM\EntityRepository; | use Doctrine\ORM\EntityRepository; | ||||
| use Symfony\Component\HttpKernel\KernelInterface; | use Symfony\Component\HttpKernel\KernelInterface; | ||||
| @@ -63,11 +62,6 @@ final class DocumentObjectFactory extends ModelFactory | |||||
| $randBool = (bool)random_int(0, 1); | $randBool = (bool)random_int(0, 1); | ||||
| return [ | return [ | ||||
| 'file' => new ReplacingFile($randomFile), | 'file' => new ReplacingFile($randomFile), | ||||
| 'createdBy' => UserFactory::random(), | |||||
| 'name' => self::faker()->randomElement(FakeValues::BUSINESS_FILE_NAMES), | |||||
| 'description' => self::faker()->text(), | |||||
| 'partner' => $randBool ? PartnerFactory::random() : null, | |||||
| 'product' => !$randBool ? ProductFactory::random() : null, | |||||
| ]; | ]; | ||||
| } | } | ||||
| @@ -52,7 +52,7 @@ final class UserFactory extends ModelFactory | |||||
| 'email' => self::faker()->email(), | 'email' => self::faker()->email(), | ||||
| 'firstName' => self::faker()->firstName(), | 'firstName' => self::faker()->firstName(), | ||||
| 'lastName' => self::faker()->lastName(), | 'lastName' => self::faker()->lastName(), | ||||
| 'image' => MediaObjectUserFactory::createOne(), | |||||
| 'image' => MediaObjectUserFactory::random(), | |||||
| 'password' => "test", | 'password' => "test", | ||||
| 'roles' => [], | 'roles' => [], | ||||
| ]; | ]; | ||||
| @@ -0,0 +1,79 @@ | |||||
| <?php | |||||
| namespace App\Mapper; | |||||
| use App\ApiResource\DocumentApi; | |||||
| use App\Entity\Document; | |||||
| use App\Entity\Partner; | |||||
| use App\Entity\Product; | |||||
| use App\Entity\User; | |||||
| use App\Repository\DocumentRepository; | |||||
| use Symfony\Bundle\SecurityBundle\Security; | |||||
| use Symfonycasts\MicroMapper\AsMapper; | |||||
| use Symfonycasts\MicroMapper\MapperInterface; | |||||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | |||||
| #[AsMapper(from: DocumentApi::class, to: Document::class)] | |||||
| class DocumentApiToEntityMapper implements MapperInterface | |||||
| { | |||||
| public function __construct( | |||||
| private DocumentRepository $repository, | |||||
| private Security $security, | |||||
| private MicroMapperInterface $microMapper, | |||||
| ) | |||||
| { | |||||
| } | |||||
| public function load(object $from, string $toClass, array $context): object | |||||
| { | |||||
| $dto = $from; | |||||
| assert($dto instanceof DocumentApi); | |||||
| if ($dto->id) { | |||||
| $entity = $this->repository->find($dto->id); | |||||
| } else { | |||||
| $user = $this->security->getUser(); | |||||
| assert($user instanceof User); | |||||
| if ($dto->documentObject === null) { | |||||
| throw new \Exception('Document object missing'); | |||||
| } | |||||
| $entity = new Document($user, $dto->documentObject); | |||||
| } | |||||
| if (!$entity) { | |||||
| throw new \Exception('Document not found'); | |||||
| } | |||||
| return $entity; | |||||
| } | |||||
| public function populate(object $from, object $to, array $context): object | |||||
| { | |||||
| $dto = $from; | |||||
| assert($dto instanceof DocumentApi); | |||||
| $entity = $to; | |||||
| assert($entity instanceof Document); | |||||
| $entity->setName($dto->name); | |||||
| $entity->setDescription($dto->description); | |||||
| if ($dto->partner !== null) { | |||||
| $entity->setPartner( | |||||
| $this->microMapper->map($dto->partner, Partner::class, [ | |||||
| MicroMapperInterface::MAX_DEPTH => 1, | |||||
| ]) | |||||
| ); | |||||
| } | |||||
| if ($dto->product !== null) { | |||||
| $entity->setProduct( | |||||
| $this->microMapper->map($dto->product, Product::class, [ | |||||
| MicroMapperInterface::MAX_DEPTH => 1, | |||||
| ]) | |||||
| ); | |||||
| } | |||||
| if ($dto->documentObject?->getId() !== $entity->getDocumentObject()?->getId()) { | |||||
| $entity->setDocumentObject($dto->documentObject); | |||||
| } | |||||
| return $entity; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,70 @@ | |||||
| <?php | |||||
| namespace App\Mapper; | |||||
| use App\ApiResource\CommentApi; | |||||
| use App\ApiResource\DocumentApi; | |||||
| use App\ApiResource\PartnerApi; | |||||
| use App\ApiResource\ProductApi; | |||||
| use App\ApiResource\UserApi; | |||||
| use App\ApiResource\PostingApi; | |||||
| use App\Entity\Comment; | |||||
| use App\Entity\Document; | |||||
| use Symfonycasts\MicroMapper\AsMapper; | |||||
| use Symfonycasts\MicroMapper\MapperInterface; | |||||
| use Symfonycasts\MicroMapper\MicroMapperInterface; | |||||
| #[AsMapper(from: Document::class, to: DocumentApi::class)] | |||||
| class DocumentEntityToApiMapper implements MapperInterface | |||||
| { | |||||
| public function __construct( | |||||
| private MicroMapperInterface $microMapper | |||||
| ) | |||||
| { | |||||
| } | |||||
| public function load(object $from, string $toClass, array $context): object | |||||
| { | |||||
| $entity = $from; | |||||
| assert($entity instanceof Document); | |||||
| $dto = new DocumentApi(); | |||||
| $dto->id = $entity->getId(); | |||||
| return $dto; | |||||
| } | |||||
| public function populate(object $from, object $to, array $context): object | |||||
| { | |||||
| $entity = $from; | |||||
| $dto = $to; | |||||
| assert($entity instanceof Document); | |||||
| assert($dto instanceof DocumentApi); | |||||
| $dto->createdBy = $this->microMapper->map($entity->getCreatedBy(), UserApi::class, [ | |||||
| MicroMapperInterface::MAX_DEPTH => 1, | |||||
| ]); | |||||
| $dto->createdByName = $entity->getCreatedBy()?->getFirstName() . ' ' . $entity->getCreatedBy()?->getLastName(); | |||||
| $dto->name = $entity->getName(); | |||||
| $dto->description = $entity->getDescription(); | |||||
| if ($entity->getPartner()) { | |||||
| $dto->partner = $this->microMapper->map($entity->getPartner(), PartnerApi::class, [ | |||||
| MicroMapperInterface::MAX_DEPTH => 1, | |||||
| ]); | |||||
| $dto->partnerName = $entity->getPartner()->getName(); | |||||
| } | |||||
| if ($entity->getProduct()) { | |||||
| $dto->product = $this->microMapper->map($entity->getProduct(), ProductApi::class, [ | |||||
| MicroMapperInterface::MAX_DEPTH => 1, | |||||
| ]); | |||||
| $dto->productName = $entity->getProduct()->getName(); | |||||
| } | |||||
| $dto->documentObject = $entity->getDocumentObject(); | |||||
| $dto->createdAt = $entity->getCreatedAt(); | |||||
| return $dto; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,48 @@ | |||||
| <?php | |||||
| namespace App\Repository; | |||||
| use App\Entity\Document; | |||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | |||||
| use Doctrine\Persistence\ManagerRegistry; | |||||
| /** | |||||
| * @extends ServiceEntityRepository<Document> | |||||
| * | |||||
| * @method Document|null find($id, $lockMode = null, $lockVersion = null) | |||||
| * @method Document|null findOneBy(array $criteria, array $orderBy = null) | |||||
| * @method Document[] findAll() | |||||
| * @method Document[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||||
| */ | |||||
| class DocumentRepository extends ServiceEntityRepository | |||||
| { | |||||
| public function __construct(ManagerRegistry $registry) | |||||
| { | |||||
| parent::__construct($registry, Document::class); | |||||
| } | |||||
| // /** | |||||
| // * @return Contact[] Returns an array of Contact objects | |||||
| // */ | |||||
| // public function findByExampleField($value): array | |||||
| // { | |||||
| // return $this->createQueryBuilder('p') | |||||
| // ->andWhere('p.exampleField = :val') | |||||
| // ->setParameter('val', $value) | |||||
| // ->orderBy('p.id', 'ASC') | |||||
| // ->setMaxResults(10) | |||||
| // ->getQuery() | |||||
| // ->getResult() | |||||
| // ; | |||||
| // } | |||||
| // public function findOneBySomeField($value): ?Contact | |||||
| // { | |||||
| // return $this->createQueryBuilder('p') | |||||
| // ->andWhere('p.exampleField = :val') | |||||
| // ->setParameter('val', $value) | |||||
| // ->getQuery() | |||||
| // ->getOneOrNullResult() | |||||
| // ; | |||||
| // } | |||||
| } | |||||
| @@ -8,6 +8,7 @@ | |||||
| namespace App\Serializer; | namespace App\Serializer; | ||||
| use App\Entity\Document; | |||||
| use App\Entity\DocumentObject; | use App\Entity\DocumentObject; | ||||
| use App\Entity\MediaObject; | use App\Entity\MediaObject; | ||||
| use Symfony\Component\DependencyInjection\Attribute\AsDecorator; | use Symfony\Component\DependencyInjection\Attribute\AsDecorator; | ||||
| @@ -11,6 +11,7 @@ use App\Enum\PartnerType; | |||||
| use App\Factory\CommentFactory; | use App\Factory\CommentFactory; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectContactFactory; | use App\Factory\MediaObjectContactFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\PostingFactory; | use App\Factory\PostingFactory; | ||||
| use App\Factory\ProductFactory; | use App\Factory\ProductFactory; | ||||
| @@ -38,6 +39,7 @@ class CommentResourceTest extends KernelTestCase | |||||
| public function testPostComment(): void | public function testPostComment(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'firstName' => 'Peter', | 'firstName' => 'Peter', | ||||
| @@ -55,7 +55,7 @@ class ContactResourceTest extends KernelTestCase | |||||
| 'lastName' => 'Test', | 'lastName' => 'Test', | ||||
| 'partner' => '/api/partners/' . $partner->getId(), | 'partner' => '/api/partners/' . $partner->getId(), | ||||
| 'birthday' => '1984-02-10T00:00:00.000Z', | 'birthday' => '1984-02-10T00:00:00.000Z', | ||||
| 'image' => '/api/medias/' . $mediaObject->getId(), | |||||
| 'image' => '/api/media_objects/' . $mediaObject->getId(), | |||||
| 'position' => 'CEO', | 'position' => 'CEO', | ||||
| 'phone' => '123456789', | 'phone' => '123456789', | ||||
| 'email' => 'peter@test2.de', | 'email' => 'peter@test2.de', | ||||
| @@ -79,7 +79,7 @@ class ContactResourceTest extends KernelTestCase | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||||
| ->delete('/api/media_objects/' . $mediaObject->getId(), [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -7,9 +7,10 @@ | |||||
| namespace App\Tests\Functional; | namespace App\Tests\Functional; | ||||
| use App\Factory\DocumentFactory; | |||||
| use App\Factory\DocumentObjectFactory; | use App\Factory\DocumentObjectFactory; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectProductFactory; | |||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\ProductFactory; | use App\Factory\ProductFactory; | ||||
| use App\Factory\UserFactory; | use App\Factory\UserFactory; | ||||
| @@ -45,6 +46,7 @@ class DocumentObjectResourceTest extends KernelTestCase | |||||
| $file = new UploadedFile($dstFile, 'image.png'); | $file = new UploadedFile($dstFile, 'image.png'); | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'firstName' => 'Peter', | 'firstName' => 'Peter', | ||||
| @@ -53,14 +55,16 @@ class DocumentObjectResourceTest extends KernelTestCase | |||||
| 'email' => 'peter@test.de', | 'email' => 'peter@test.de', | ||||
| ] | ] | ||||
| ); | ); | ||||
| MediaObjectProductFactory::createOne(); | |||||
| $partner = PartnerFactory::createOne(); | |||||
| $product = ProductFactory::createOne(); | |||||
| $documentObject = DocumentObjectFactory::createOne(); | |||||
| PartnerFactory::createOne(); | |||||
| ProductFactory::createOne(); | |||||
| $document = DocumentFactory::createOne(); | |||||
| $token = $this->JWTManager->create($user->object()); | $token = $this->JWTManager->create($user->object()); | ||||
| $this->browser() | $this->browser() | ||||
| ->get('/api/documents', [ | |||||
| ->get('/api/document_objects', [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -69,7 +73,7 @@ class DocumentObjectResourceTest extends KernelTestCase | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->post('/api/documents', [ | |||||
| ->post('/api/document_objects', [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| 'Content-Type' => 'multipart/form-data' | 'Content-Type' => 'multipart/form-data' | ||||
| @@ -77,29 +81,38 @@ class DocumentObjectResourceTest extends KernelTestCase | |||||
| 'files' => [ | 'files' => [ | ||||
| 'file' => $file, | 'file' => $file, | ||||
| ], | ], | ||||
| 'partner' => '/api/partners/' . $partner->getId(), | |||||
| 'product' => '/api/products/' . $product->getId(), | |||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/documents/1', | |||||
| ->patch('/api/documents/' . $document->getId(), | |||||
| [ | [ | ||||
| 'json' => [ | |||||
| 'documentObject' => '/api/document_objects/' . $documentObject->getId() | |||||
| ], | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| 'Content-Type' => 'application/merge-patch+json' | |||||
| ], | ], | ||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| ; | ; | ||||
| $this->browser() | |||||
| ->delete('/api/document_objects/' . $documentObject->getId(), | |||||
| [ | |||||
| 'headers' => [ | |||||
| 'Authorization' => 'Bearer ' . $token, | |||||
| ], | |||||
| ]) | |||||
| ->assertStatus(500) | |||||
| ; | |||||
| } | } | ||||
| public function testDeleteDocumentObject() | public function testDeleteDocumentObject() | ||||
| { | { | ||||
| MediaObjectProductFactory::createOne(); | |||||
| $partner = PartnerFactory::createOne(); | |||||
| $product = ProductFactory::createOne(); | |||||
| $documentsObject = DocumentObjectFactory::createOne(); | |||||
| $mediaObject = MediaObjectLogoFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'firstName' => 'Peter', | 'firstName' => 'Peter', | ||||
| @@ -109,8 +122,9 @@ class DocumentObjectResourceTest extends KernelTestCase | |||||
| ] | ] | ||||
| ); | ); | ||||
| $token = $this->JWTManager->create($user->object()); | $token = $this->JWTManager->create($user->object()); | ||||
| $documentObject = DocumentObjectFactory::createOne(); | |||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/documents/' . $documentsObject->getId(), [ | |||||
| ->delete('/api/document_objects/' . $documentObject->getId(), [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -0,0 +1,114 @@ | |||||
| <?php | |||||
| /** | |||||
| * @author Daniel Knudsen <d.knudsen@spawntree.de> | |||||
| * @date 01.03.24 | |||||
| */ | |||||
| namespace App\Tests\Functional; | |||||
| use App\Entity\DocumentObject; | |||||
| use App\Factory\DocumentFactory; | |||||
| use App\Factory\DocumentObjectFactory; | |||||
| use App\Factory\MediaObjectLogoFactory; | |||||
| use App\Factory\MediaObjectProductFactory; | |||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | |||||
| use App\Factory\ProductFactory; | |||||
| use App\Factory\UserFactory; | |||||
| use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | |||||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | |||||
| use Symfony\Component\HttpFoundation\File\UploadedFile; | |||||
| use Zenstruck\Browser\Test\HasBrowser; | |||||
| use Zenstruck\Foundry\Test\Factories; | |||||
| use Zenstruck\Foundry\Test\ResetDatabase; | |||||
| class DocumentResourceTest extends KernelTestCase | |||||
| { | |||||
| use HasBrowser; | |||||
| use ResetDatabase; | |||||
| use Factories; | |||||
| private JWTTokenManagerInterface $JWTManager; | |||||
| private string $projectDir; | |||||
| protected function setUp(): void | |||||
| { | |||||
| parent::setUp(); | |||||
| $this->JWTManager = self::getContainer()->get('lexik_jwt_authentication.jwt_manager'); | |||||
| $this->projectDir = self::getContainer()->get('kernel')->getProjectDir(); | |||||
| } | |||||
| public function testCreateDocument(): void | |||||
| { | |||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | |||||
| [ | |||||
| 'firstName' => 'Peter', | |||||
| 'lastName' => 'Test', | |||||
| 'password' => 'test', | |||||
| 'email' => 'peter@test.de', | |||||
| ] | |||||
| ); | |||||
| MediaObjectLogoFactory::createOne(); | |||||
| MediaObjectProductFactory::createOne(); | |||||
| $partner = PartnerFactory::createOne(); | |||||
| $product = ProductFactory::createOne(); | |||||
| $documentObject = DocumentObjectFactory::createOne(); | |||||
| $token = $this->JWTManager->create($user->object()); | |||||
| $this->browser() | |||||
| ->get('/api/documents', [ | |||||
| 'headers' => [ | |||||
| 'Authorization' => 'Bearer ' . $token, | |||||
| ], | |||||
| ]) | |||||
| ->assertSuccessful() | |||||
| ; | |||||
| $this->browser() | |||||
| ->post('/api/documents', [ | |||||
| 'json' => [ | |||||
| 'name' => 'my business file', | |||||
| 'description' => 'test', | |||||
| 'partner' => '/api/partners/' . $partner->getId(), | |||||
| 'product' => '/api/products/' . $product->getId(), | |||||
| 'documentObject' => '/api/document_objects/' . $documentObject->getId() | |||||
| ], | |||||
| 'headers' => [ | |||||
| 'Authorization' => 'Bearer ' . $token, | |||||
| ] | |||||
| ]) | |||||
| ->assertSuccessful() | |||||
| ; | |||||
| } | |||||
| public function testDeleteDocument() | |||||
| { | |||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | |||||
| [ | |||||
| 'firstName' => 'Peter', | |||||
| 'lastName' => 'Test', | |||||
| 'password' => 'test', | |||||
| 'email' => 'peter@test.de', | |||||
| 'roles' => ["ROLE_ADMIN"] | |||||
| ] | |||||
| ); | |||||
| $token = $this->JWTManager->create($user->object()); | |||||
| DocumentObjectFactory::createOne(); | |||||
| PartnerFactory::createOne(); | |||||
| ProductFactory::createOne(); | |||||
| $document = DocumentFactory::createOne(); | |||||
| $this->browser() | |||||
| ->delete('/api/documents/' . $document->getId(), [ | |||||
| 'headers' => [ | |||||
| 'Authorization' => 'Bearer ' . $token, | |||||
| ], | |||||
| ]) | |||||
| ->assertSuccessful() | |||||
| ; | |||||
| } | |||||
| } | |||||
| @@ -8,6 +8,7 @@ | |||||
| namespace App\Tests\Functional; | namespace App\Tests\Functional; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\UserFactory; | use App\Factory\UserFactory; | ||||
| use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | ||||
| @@ -42,6 +43,7 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| $file = new UploadedFile($dstFile, 'image.png'); | $file = new UploadedFile($dstFile, 'image.png'); | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'firstName' => 'Peter', | 'firstName' => 'Peter', | ||||
| @@ -53,7 +55,7 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| $token = $this->JWTManager->create($user->object()); | $token = $this->JWTManager->create($user->object()); | ||||
| $this->browser() | $this->browser() | ||||
| ->get('/api/medias', [ | |||||
| ->get('/api/media_objects', [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -62,7 +64,7 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->post('/api/medias', [ | |||||
| ->post('/api/media_objects', [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| 'Content-Type' => 'multipart/form-data' | 'Content-Type' => 'multipart/form-data' | ||||
| @@ -79,7 +81,7 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| ->patch('/api/partners/' . $partner->getId(), | ->patch('/api/partners/' . $partner->getId(), | ||||
| [ | [ | ||||
| 'json' => [ | 'json' => [ | ||||
| 'logo' => '/api/medias/1' | |||||
| 'logo' => '/api/media_objects/1' | |||||
| ], | ], | ||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| @@ -90,7 +92,7 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/medias/1', | |||||
| ->delete('/api/media_objects/1', | |||||
| [ | [ | ||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| @@ -102,6 +104,7 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| public function testDeleteMediaObject() | public function testDeleteMediaObject() | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $mediaObject = MediaObjectLogoFactory::createOne(); | $mediaObject = MediaObjectLogoFactory::createOne(); | ||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| @@ -113,7 +116,7 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| ); | ); | ||||
| $token = $this->JWTManager->create($user->object()); | $token = $this->JWTManager->create($user->object()); | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||||
| ->delete('/api/media_objects/' . $mediaObject->getId(), [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -8,6 +8,7 @@ | |||||
| namespace App\Tests\Functional; | namespace App\Tests\Functional; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\PartnerFollowFactory; | use App\Factory\PartnerFollowFactory; | ||||
| use App\Factory\UserFactory; | use App\Factory\UserFactory; | ||||
| @@ -33,6 +34,7 @@ class PartnerFollowResourceTest extends KernelTestCase | |||||
| public function testPostPartnerFollow(): void | public function testPostPartnerFollow(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'firstName' => 'Peter', | 'firstName' => 'Peter', | ||||
| @@ -9,6 +9,7 @@ namespace App\Tests\Functional; | |||||
| use App\Enum\PartnerType; | use App\Enum\PartnerType; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\ProductFactory; | use App\Factory\ProductFactory; | ||||
| use App\Factory\SaleFactory; | use App\Factory\SaleFactory; | ||||
| @@ -35,6 +36,7 @@ class PartnerResourceTest extends KernelTestCase | |||||
| public function testPostPartner(): void | public function testPostPartner(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'email' => 'peter@test.de', | 'email' => 'peter@test.de', | ||||
| @@ -62,7 +64,7 @@ class PartnerResourceTest extends KernelTestCase | |||||
| 'city' => 'test city', | 'city' => 'test city', | ||||
| 'country' => 'test country', | 'country' => 'test country', | ||||
| 'website' => 'wwe.test.de', | 'website' => 'wwe.test.de', | ||||
| 'logo' => '/api/medias/' . $mediaObject->getId(), | |||||
| 'logo' => '/api/media_objects/' . $mediaObject->getId(), | |||||
| ], | ], | ||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| @@ -86,7 +88,7 @@ class PartnerResourceTest extends KernelTestCase | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||||
| ->delete('/api/media_objects/' . $mediaObject->getId(), [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -10,6 +10,7 @@ namespace App\Tests\Functional; | |||||
| use App\Factory\ContactFactory; | use App\Factory\ContactFactory; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectContactFactory; | use App\Factory\MediaObjectContactFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\PostingFactory; | use App\Factory\PostingFactory; | ||||
| use App\Factory\ProductFactory; | use App\Factory\ProductFactory; | ||||
| @@ -37,6 +38,7 @@ class PostingResourceTest extends KernelTestCase | |||||
| public function testPostPosting(): void | public function testPostPosting(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'email' => 'peter@test.de', | 'email' => 'peter@test.de', | ||||
| @@ -7,13 +7,8 @@ | |||||
| namespace App\Tests\Functional; | namespace App\Tests\Functional; | ||||
| use App\Factory\ContactFactory; | |||||
| use App\Factory\MediaObjectLogoFactory; | |||||
| use App\Factory\MediaObjectContactFactory; | |||||
| use App\Factory\MediaObjectProductFactory; | use App\Factory\MediaObjectProductFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | use App\Factory\MediaObjectUserFactory; | ||||
| use App\Factory\PartnerFactory; | |||||
| use App\Factory\PostingFactory; | |||||
| use App\Factory\UserFactory; | use App\Factory\UserFactory; | ||||
| use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | ||||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||||
| @@ -37,6 +32,7 @@ class ProductResourceTest extends KernelTestCase | |||||
| public function testPostProduct(): void | public function testPostProduct(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'email' => 'peter@test.de', | 'email' => 'peter@test.de', | ||||
| @@ -54,7 +50,7 @@ class ProductResourceTest extends KernelTestCase | |||||
| 'json' => [ | 'json' => [ | ||||
| 'name' => 'Test', | 'name' => 'Test', | ||||
| 'description' => 'more test', | 'description' => 'more test', | ||||
| 'image' => '/api/medias/' . $mediaObject->getId(), | |||||
| 'image' => '/api/media_objects/' . $mediaObject->getId(), | |||||
| ], | ], | ||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| @@ -11,6 +11,7 @@ use App\Enum\PartnerType; | |||||
| use App\Factory\CommentFactory; | use App\Factory\CommentFactory; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectContactFactory; | use App\Factory\MediaObjectContactFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\PostingFactory; | use App\Factory\PostingFactory; | ||||
| use App\Factory\TaskFactory; | use App\Factory\TaskFactory; | ||||
| @@ -38,6 +39,7 @@ class TaskNoteResourceTest extends KernelTestCase | |||||
| public function testPostTaskNote(): void | public function testPostTaskNote(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'firstName' => 'Peter', | 'firstName' => 'Peter', | ||||
| @@ -12,6 +12,7 @@ use App\Factory\CommentFactory; | |||||
| use App\Factory\ContactFactory; | use App\Factory\ContactFactory; | ||||
| use App\Factory\MediaObjectLogoFactory; | use App\Factory\MediaObjectLogoFactory; | ||||
| use App\Factory\MediaObjectContactFactory; | use App\Factory\MediaObjectContactFactory; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\PartnerFactory; | use App\Factory\PartnerFactory; | ||||
| use App\Factory\PostingFactory; | use App\Factory\PostingFactory; | ||||
| use App\Factory\UserFactory; | use App\Factory\UserFactory; | ||||
| @@ -37,6 +38,7 @@ class TaskResourceTest extends KernelTestCase | |||||
| public function testPostTask(): void | public function testPostTask(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'firstName' => 'Peter', | 'firstName' => 'Peter', | ||||
| @@ -7,6 +7,7 @@ | |||||
| namespace App\Tests\Functional; | namespace App\Tests\Functional; | ||||
| use App\Factory\MediaObjectUserFactory; | |||||
| use App\Factory\UserFactory; | use App\Factory\UserFactory; | ||||
| use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | ||||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||||
| @@ -31,6 +32,7 @@ class UserResourceTest extends KernelTestCase | |||||
| public function testPostUser(): void | public function testPostUser(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| UserFactory::createOne( | UserFactory::createOne( | ||||
| [ | [ | ||||
| 'email' => 'peter@test.de', | 'email' => 'peter@test.de', | ||||
| @@ -88,6 +90,7 @@ class UserResourceTest extends KernelTestCase | |||||
| public function testPostUserNoAdmin(): void | public function testPostUserNoAdmin(): void | ||||
| { | { | ||||
| MediaObjectUserFactory::createOne(); | |||||
| $user = UserFactory::createOne( | $user = UserFactory::createOne( | ||||
| [ | [ | ||||
| 'email' => 'peter@test.de', | 'email' => 'peter@test.de', | ||||