From b65b99de1344694e2f39267a4cc182aaac66b0f2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 7 Jun 2024 11:36:35 +0200 Subject: [PATCH] added fields to entities --- ...240516084219.php => Version20240607092001.php} | 8 ++++---- src/ApiResource/TaskApi.php | 1 - src/ApiResource/TaskNoteApi.php | 4 ++++ src/ApiResource/UserApi.php | 2 ++ src/DataFixtures/AppFixtures.php | 4 +++- src/DataFixtures/FakeValues.php | 2 +- src/Entity/Product.php | 2 +- src/Entity/TaskNote.php | 14 ++++++++++++++ src/Entity/User.php | 14 ++++++++++++++ src/Enum/TaskNoteContactType.php | 15 +++++++++++++++ src/Factory/ProductFactory.php | 2 +- src/Factory/TaskNoteFactory.php | 2 ++ src/Factory/UserFactory.php | 1 + src/Mapper/TaskNoteApiToEntityMapper.php | 1 + src/Mapper/TaskNoteEntityToApiMapper.php | 2 ++ src/Mapper/UserApiToEntityMapper.php | 2 +- src/Mapper/UserEntityToApiMapper.php | 1 + 17 files changed, 67 insertions(+), 10 deletions(-) rename migrations/{Version20240516084219.php => Version20240607092001.php} (94%) create mode 100644 src/Enum/TaskNoteContactType.php diff --git a/migrations/Version20240516084219.php b/migrations/Version20240607092001.php similarity index 94% rename from migrations/Version20240516084219.php rename to migrations/Version20240607092001.php index f618736..71e9f36 100644 --- a/migrations/Version20240516084219.php +++ b/migrations/Version20240607092001.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240516084219 extends AbstractMigration +final class Version20240607092001 extends AbstractMigration { public function getDescription(): string { @@ -30,11 +30,11 @@ final class Version20240516084219 extends AbstractMigration $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), UNIQUE INDEX unique_follow (user_id, partner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('CREATE TABLE partner_product (id INT AUTO_INCREMENT NOT NULL, partner_id INT NOT NULL, product_id INT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_14A067B09393F8FE (partner_id), INDEX IDX_14A067B04584665A (product_id), UNIQUE INDEX unique_partner_product (partner_id, product_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, product_id INT NOT 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), INDEX IDX_BD275D734584665A (product_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, created_by_id INT NOT NULL, navision_id INT UNSIGNED DEFAULT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_D34A04ADB0FD8AF9 (navision_id), INDEX IDX_D34A04AD3DA5256D (image_id), INDEX IDX_D34A04ADB03A8386 (created_by_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, created_by_id INT NOT NULL, navision_id INT UNSIGNED DEFAULT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_D34A04ADB0FD8AF9 (navision_id), UNIQUE INDEX UNIQ_D34A04AD5E237E06 (name), INDEX IDX_D34A04AD3DA5256D (image_id), INDEX IDX_D34A04ADB03A8386 (created_by_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, quantity INT UNSIGNED NOT 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 task (id INT AUTO_INCREMENT NOT NULL, created_by_id INT NOT NULL, assigned_to_id INT NOT NULL, product_id INT NOT NULL, partner_id INT DEFAULT NULL, contact_id INT DEFAULT NULL, headline VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, due_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', prio VARCHAR(255) NOT NULL, completed TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_527EDB25B03A8386 (created_by_id), INDEX IDX_527EDB25F4BD7827 (assigned_to_id), INDEX IDX_527EDB254584665A (product_id), INDEX IDX_527EDB259393F8FE (partner_id), INDEX IDX_527EDB25E7A1254A (contact_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE task_note (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, task_id INT NOT NULL, message LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_BC0E6E6F7E3C61F9 (owner_id), INDEX IDX_BC0E6E6F8DB60186 (task_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE `user` (id INT AUTO_INCREMENT NOT NULL, image_id INT DEFAULT NULL, email VARCHAR(180) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, active TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), INDEX IDX_8D93D6493DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE task_note (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, task_id INT NOT NULL, message LONGTEXT NOT NULL, type VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_BC0E6E6F7E3C61F9 (owner_id), INDEX IDX_BC0E6E6F8DB60186 (task_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE `user` (id INT AUTO_INCREMENT NOT NULL, image_id INT DEFAULT NULL, email VARCHAR(180) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, goals LONGTEXT DEFAULT NULL, roles JSON NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, active TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), INDEX IDX_8D93D6493DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('CREATE TABLE user_product (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, product_id INT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_8B471AA7A76ED395 (user_id), INDEX IDX_8B471AA74584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C7E3C61F9 FOREIGN KEY (owner_id) REFERENCES `user` (id)'); $this->addSql('ALTER TABLE comment ADD CONSTRAINT FK_9474526C9AE985F6 FOREIGN KEY (posting_id) REFERENCES posting (id) ON DELETE CASCADE'); diff --git a/src/ApiResource/TaskApi.php b/src/ApiResource/TaskApi.php index 4978448..2fe9391 100644 --- a/src/ApiResource/TaskApi.php +++ b/src/ApiResource/TaskApi.php @@ -65,7 +65,6 @@ class TaskApi #[Assert\NotBlank] public ?string $headline = null; - #[Assert\NotBlank] public ?string $description = null; /** diff --git a/src/ApiResource/TaskNoteApi.php b/src/ApiResource/TaskNoteApi.php index 2d9a4fa..0d79a7c 100644 --- a/src/ApiResource/TaskNoteApi.php +++ b/src/ApiResource/TaskNoteApi.php @@ -13,6 +13,7 @@ use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; use App\Entity\TaskNote; +use App\Enum\TaskNoteContactType; use App\Interface\OwnerInterface; use App\State\EntityClassDtoStateProcessor; use App\State\EntityToDtoStateProvider; @@ -75,6 +76,9 @@ class TaskNoteApi implements OwnerInterface #[NotBlank] public ?TaskApi $taskIri = null; + #[NotBlank] + public TaskNoteContactType $type; + #[ApiProperty(writable: false)] public ?\DateTimeImmutable $createdAt = null; diff --git a/src/ApiResource/UserApi.php b/src/ApiResource/UserApi.php index 0caf55a..4cd0ce1 100644 --- a/src/ApiResource/UserApi.php +++ b/src/ApiResource/UserApi.php @@ -62,6 +62,8 @@ class UserApi #[Assert\NotBlank] public ?string $lastName = null; + public ?string $goals = null; + public ?MediaObject $image = null; #[ApiProperty(writable: false)] diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php index 99f9dc9..779e6fa 100644 --- a/src/DataFixtures/AppFixtures.php +++ b/src/DataFixtures/AppFixtures.php @@ -128,9 +128,11 @@ class AppFixtures extends Fixture ); } - for ($i = 0; $i < 100; $i++) { + $numProducts = count(FakeValues::PRODUCTS); + for ($i = 0; $i < $numProducts; $i++) { ProductFactory::createOne( [ + 'name' => FakeValues::PRODUCTS[$i], 'image' => MediaObjectProductFactory::createOne(), 'createdBy' => $adminD ] diff --git a/src/DataFixtures/FakeValues.php b/src/DataFixtures/FakeValues.php index 10602bc..0c9bc61 100644 --- a/src/DataFixtures/FakeValues.php +++ b/src/DataFixtures/FakeValues.php @@ -201,7 +201,7 @@ class FakeValues 'SynthoQuanta Elixir', 'NebulaCryo Blend', 'HydroQuell Acid', 'RadiantFusion Serum', 'ElectroCryo-X', 'MolecularQuanta Acid', 'BioSpark Elixir', 'QuantumRadiance Blend', 'NanoFlare Acid', 'MagnaQuanta Serum', 'Luminex Catalyst-X', 'CryoFusion Elixir', 'NeuroQuell Blend', 'PlasmaMyst Acid', 'SynthoRadiance Serum', 'QuantumVortex-X', 'NebulaSpark Blend', 'HydroGlow Catalyst', 'RadiantQuanta Acid', 'ElectroMyst Elixir', 'MegaQuell Serum', - 'CryoVortex Acid', 'NanoRadiance Blend', 'QuantumFusion Serum', 'SynthoFlare-X', 'PlasmaQuell Acid', 'MolecularGlow Blend', 'Luminex Catalyst-X', + 'CryoVortex Acid', 'NanoRadiance Blend', 'QuantumFusion Serum', 'SynthoFlare-X', 'PlasmaQuell Acid', 'MolecularGlow Blend', 'Luminex Catalyst-Z', 'ElectroWave Serum', 'CryoMyst Acid', 'NeuroFusion Elixir', 'NanoSizzle Blend-X', 'QuantumPulse Acid', 'RadiantFlare Serum', 'BioQuanta Catalyst', ]; diff --git a/src/Entity/Product.php b/src/Entity/Product.php index 067559e..26fc862 100644 --- a/src/Entity/Product.php +++ b/src/Entity/Product.php @@ -19,7 +19,7 @@ class Product #[ORM\Column(type: "integer", unique: true, nullable: true, options: ["unsigned" => true])] protected int $navisionId; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255, unique: true)] private ?string $name = null; #[ORM\Column(type: Types::TEXT, nullable: true)] diff --git a/src/Entity/TaskNote.php b/src/Entity/TaskNote.php index 9c609c4..c82e44c 100644 --- a/src/Entity/TaskNote.php +++ b/src/Entity/TaskNote.php @@ -2,6 +2,7 @@ namespace App\Entity; +use App\Enum\TaskNoteContactType; use App\Repository\TaskNoteRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; @@ -25,6 +26,9 @@ class TaskNote #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] private ?Task $task = null; + #[ORM\Column(type: 'string', enumType: TaskNoteContactType::class)] + private TaskNoteContactType $type; + #[ORM\Column] private ?\DateTimeImmutable $createdAt = null; @@ -76,6 +80,16 @@ class TaskNote return $this; } + public function getType(): TaskNoteContactType + { + return $this->type; + } + + public function setType(TaskNoteContactType $type): void + { + $this->type = $type; + } + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; diff --git a/src/Entity/User.php b/src/Entity/User.php index 9df6cf1..da0692f 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -5,6 +5,7 @@ namespace App\Entity; use App\Repository\UserRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; @@ -31,6 +32,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] private ?MediaObject $image = null; + #[ORM\Column(type: Types::TEXT, nullable: true)] + private ?string $goals = null; + #[ORM\Column] private array $roles = []; @@ -171,6 +175,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + public function getGoals(): ?string + { + return $this->goals; + } + + public function setGoals(?string $goals): void + { + $this->goals = $goals; + } + public function getImage(): ?MediaObject { return $this->image; diff --git a/src/Enum/TaskNoteContactType.php b/src/Enum/TaskNoteContactType.php new file mode 100644 index 0000000..3c26466 --- /dev/null +++ b/src/Enum/TaskNoteContactType.php @@ -0,0 +1,15 @@ + + * @date 20.12.23 + */ + + +namespace App\Enum; + + +enum TaskNoteContactType: string { + case Personal = 'personal'; + case Phone = 'phone'; + case Email = 'email'; +} diff --git a/src/Factory/ProductFactory.php b/src/Factory/ProductFactory.php index e7ff6de..ce1c969 100644 --- a/src/Factory/ProductFactory.php +++ b/src/Factory/ProductFactory.php @@ -48,7 +48,7 @@ final class ProductFactory extends ModelFactory protected function getDefaults(): array { return [ - 'name' => self::faker()->randomElement(FakeValues::PRODUCTS), + 'name' => self::faker()->word().random_int(1,999999), 'description' => self::faker()->text(), 'createdBy' => UserFactory::random() ]; diff --git a/src/Factory/TaskNoteFactory.php b/src/Factory/TaskNoteFactory.php index 142bdd0..bf1a0e3 100644 --- a/src/Factory/TaskNoteFactory.php +++ b/src/Factory/TaskNoteFactory.php @@ -3,6 +3,7 @@ namespace App\Factory; use App\Entity\TaskNote; +use App\Enum\TaskNoteContactType; use App\Repository\TaskNoteRepository; use Zenstruck\Foundry\ModelFactory; use Zenstruck\Foundry\Proxy; @@ -51,6 +52,7 @@ final class TaskNoteFactory extends ModelFactory 'message' => self::faker()->text(), 'owner' => UserFactory::random(), 'task' => TaskFactory::random(), + 'type' => self::faker()->randomElement(TaskNoteContactType::cases()), ]; } diff --git a/src/Factory/UserFactory.php b/src/Factory/UserFactory.php index 845be9d..04c4447 100644 --- a/src/Factory/UserFactory.php +++ b/src/Factory/UserFactory.php @@ -52,6 +52,7 @@ final class UserFactory extends ModelFactory 'email' => self::faker()->email(), 'firstName' => self::faker()->firstName(), 'lastName' => self::faker()->lastName(), + 'goals' => self::faker()->text(), 'password' => "test", 'roles' => [], ]; diff --git a/src/Mapper/TaskNoteApiToEntityMapper.php b/src/Mapper/TaskNoteApiToEntityMapper.php index 3ccb753..aec7c9c 100644 --- a/src/Mapper/TaskNoteApiToEntityMapper.php +++ b/src/Mapper/TaskNoteApiToEntityMapper.php @@ -58,6 +58,7 @@ class TaskNoteApiToEntityMapper implements MapperInterface $entity = $to; assert($entity instanceof TaskNote); $entity->setMessage($dto->message); + $entity->setType($dto->type); return $entity; } diff --git a/src/Mapper/TaskNoteEntityToApiMapper.php b/src/Mapper/TaskNoteEntityToApiMapper.php index 290d524..c077207 100644 --- a/src/Mapper/TaskNoteEntityToApiMapper.php +++ b/src/Mapper/TaskNoteEntityToApiMapper.php @@ -46,6 +46,8 @@ class TaskNoteEntityToApiMapper implements MapperInterface MicroMapperInterface::MAX_DEPTH => 1, ]); + $dto->type = $entity->getType(); + $dto->createdAt = $entity->getCreatedAt(); return $dto; diff --git a/src/Mapper/UserApiToEntityMapper.php b/src/Mapper/UserApiToEntityMapper.php index 1d0025f..912439f 100644 --- a/src/Mapper/UserApiToEntityMapper.php +++ b/src/Mapper/UserApiToEntityMapper.php @@ -19,7 +19,6 @@ class UserApiToEntityMapper implements MapperInterface public function __construct( private UserRepository $repository, private UserPasswordHasherInterface $userPasswordHasher, - private MicroMapperInterface $microMapper, private PropertyAccessorInterface $propertyAccessor, ) { @@ -48,6 +47,7 @@ class UserApiToEntityMapper implements MapperInterface $entity->setEmail($dto->email); $entity->setFirstName($dto->firstName); $entity->setLastName($dto->lastName); + $entity->setGoals($dto->goals); if ($dto->password) { $entity->setPassword($this->userPasswordHasher->hashPassword($entity, $dto->password)); } diff --git a/src/Mapper/UserEntityToApiMapper.php b/src/Mapper/UserEntityToApiMapper.php index 463c744..1f9a498 100644 --- a/src/Mapper/UserEntityToApiMapper.php +++ b/src/Mapper/UserEntityToApiMapper.php @@ -42,6 +42,7 @@ class UserEntityToApiMapper implements MapperInterface $dto->email = $entity->getEmail(); $dto->firstName = $entity->getFirstName(); $dto->lastName = $entity->getLastName(); + $dto->goals = $entity->getGoals(); $dto->image = $entity->getImage(); $dto->imageUrl = $this->fileUrlService->getFileUrl($entity->getImage()); $dto->fullName = $entity->getFirstName() . " " . $entity->getLastName();