Przeglądaj źródła

added fields to entities

master
Daniel 1 rok temu
rodzic
commit
b65b99de13
17 zmienionych plików z 67 dodań i 10 usunięć
  1. +4
    -4
      migrations/Version20240607092001.php
  2. +0
    -1
      src/ApiResource/TaskApi.php
  3. +4
    -0
      src/ApiResource/TaskNoteApi.php
  4. +2
    -0
      src/ApiResource/UserApi.php
  5. +3
    -1
      src/DataFixtures/AppFixtures.php
  6. +1
    -1
      src/DataFixtures/FakeValues.php
  7. +1
    -1
      src/Entity/Product.php
  8. +14
    -0
      src/Entity/TaskNote.php
  9. +14
    -0
      src/Entity/User.php
  10. +15
    -0
      src/Enum/TaskNoteContactType.php
  11. +1
    -1
      src/Factory/ProductFactory.php
  12. +2
    -0
      src/Factory/TaskNoteFactory.php
  13. +1
    -0
      src/Factory/UserFactory.php
  14. +1
    -0
      src/Mapper/TaskNoteApiToEntityMapper.php
  15. +2
    -0
      src/Mapper/TaskNoteEntityToApiMapper.php
  16. +1
    -1
      src/Mapper/UserApiToEntityMapper.php
  17. +1
    -0
      src/Mapper/UserEntityToApiMapper.php

migrations/Version20240516084219.php → migrations/Version20240607092001.php Wyświetl plik

@@ -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');

+ 0
- 1
src/ApiResource/TaskApi.php Wyświetl plik

@@ -65,7 +65,6 @@ class TaskApi
#[Assert\NotBlank]
public ?string $headline = null;

#[Assert\NotBlank]
public ?string $description = null;

/**


+ 4
- 0
src/ApiResource/TaskNoteApi.php Wyświetl plik

@@ -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;



+ 2
- 0
src/ApiResource/UserApi.php Wyświetl plik

@@ -62,6 +62,8 @@ class UserApi
#[Assert\NotBlank]
public ?string $lastName = null;

public ?string $goals = null;

public ?MediaObject $image = null;

#[ApiProperty(writable: false)]


+ 3
- 1
src/DataFixtures/AppFixtures.php Wyświetl plik

@@ -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
]


+ 1
- 1
src/DataFixtures/FakeValues.php Wyświetl plik

@@ -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',
];



+ 1
- 1
src/Entity/Product.php Wyświetl plik

@@ -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)]


+ 14
- 0
src/Entity/TaskNote.php Wyświetl plik

@@ -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;


+ 14
- 0
src/Entity/User.php Wyświetl plik

@@ -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;


+ 15
- 0
src/Enum/TaskNoteContactType.php Wyświetl plik

@@ -0,0 +1,15 @@
<?php
/**
* @author Daniel Knudsen <d.knudsen@spawntree.de>
* @date 20.12.23
*/


namespace App\Enum;


enum TaskNoteContactType: string {
case Personal = 'personal';
case Phone = 'phone';
case Email = 'email';
}

+ 1
- 1
src/Factory/ProductFactory.php Wyświetl plik

@@ -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()
];


+ 2
- 0
src/Factory/TaskNoteFactory.php Wyświetl plik

@@ -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()),
];
}



+ 1
- 0
src/Factory/UserFactory.php Wyświetl plik

@@ -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' => [],
];


+ 1
- 0
src/Mapper/TaskNoteApiToEntityMapper.php Wyświetl plik

@@ -58,6 +58,7 @@ class TaskNoteApiToEntityMapper implements MapperInterface
$entity = $to;
assert($entity instanceof TaskNote);
$entity->setMessage($dto->message);
$entity->setType($dto->type);

return $entity;
}


+ 2
- 0
src/Mapper/TaskNoteEntityToApiMapper.php Wyświetl plik

@@ -46,6 +46,8 @@ class TaskNoteEntityToApiMapper implements MapperInterface
MicroMapperInterface::MAX_DEPTH => 1,
]);

$dto->type = $entity->getType();

$dto->createdAt = $entity->getCreatedAt();

return $dto;


+ 1
- 1
src/Mapper/UserApiToEntityMapper.php Wyświetl plik

@@ -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));
}


+ 1
- 0
src/Mapper/UserEntityToApiMapper.php Wyświetl plik

@@ -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();


Ładowanie…
Anuluj
Zapisz