diff --git a/migrations/Version20240326161210.php b/migrations/Version20240327103616.php similarity index 96% rename from migrations/Version20240326161210.php rename to migrations/Version20240327103616.php index 9023414..74be294 100644 --- a/migrations/Version20240326161210.php +++ b/migrations/Version20240327103616.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240326161210 extends AbstractMigration +final class Version20240327103616 extends AbstractMigration { public function getDescription(): string { @@ -25,7 +25,7 @@ final class Version20240326161210 extends AbstractMigration $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 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, description LONGTEXT DEFAULT 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), 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 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'); diff --git a/src/ApiResource/PartnerApi.php b/src/ApiResource/PartnerApi.php index 07fd8d0..686269f 100644 --- a/src/ApiResource/PartnerApi.php +++ b/src/ApiResource/PartnerApi.php @@ -62,6 +62,8 @@ class PartnerApi #[NotBlank] public PartnerType $partnerType; + public ?string $description = null; + public ?string $street = null; public ?string $streetNo = null; diff --git a/src/ApiResource/SaleApi.php b/src/ApiResource/SaleApi.php index 4320ef7..008f9c3 100644 --- a/src/ApiResource/SaleApi.php +++ b/src/ApiResource/SaleApi.php @@ -13,6 +13,7 @@ use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiResource; use App\Entity\Sale; +use App\Enum\PartnerType; use App\Interface\OwnerInterface; use App\State\EntityClassDtoStateProcessor; use App\State\EntityToDtoStateProvider; @@ -61,6 +62,9 @@ class SaleApi implements OwnerInterface #[ApiProperty(writable: true)] public ?PartnerApi $partner = null; + #[ApiProperty(writable: false)] + public PartnerType $partnerType; + #[ApiProperty(writable: false)] public ?string $partnerName = null; diff --git a/src/Entity/Partner.php b/src/Entity/Partner.php index 49bf82e..e3825cc 100644 --- a/src/Entity/Partner.php +++ b/src/Entity/Partner.php @@ -6,6 +6,7 @@ use App\Enum\PartnerType; use App\Repository\PartnerRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: PartnerRepository::class)] @@ -22,6 +23,9 @@ class Partner #[ORM\Column(type: 'string', enumType: PartnerType::class)] private PartnerType $type; + #[ORM\Column(type: Types::TEXT, nullable: true)] + private ?string $description = null; + #[ORM\Column(length: 255, nullable: true)] private ?string $street = null; @@ -98,6 +102,16 @@ class Partner $this->type = $type; } + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): void + { + $this->description = $description; + } + public function getStreet(): ?string { return $this->street; diff --git a/src/Factory/PartnerFactory.php b/src/Factory/PartnerFactory.php index 0460ff1..8a95d81 100644 --- a/src/Factory/PartnerFactory.php +++ b/src/Factory/PartnerFactory.php @@ -52,6 +52,7 @@ final class PartnerFactory extends ModelFactory return [ 'name' => self::faker()->randomElement(FakeValues::COMPANY_NAMES)." ".self::faker()->randomElement(FakeValues::COMPANY_LEGAL_FORMS), 'type' => self::faker()->randomElement(PartnerType::cases()), + 'description' => self::faker()->text(), 'street' => self::faker()->randomElement(FakeValues::STREETS), 'streetNo' => self::faker()->numberBetween(1,1000), 'zip' => self::faker()->numberBetween(1000,10000), diff --git a/src/Mapper/PartnerApiToEntityMapper.php b/src/Mapper/PartnerApiToEntityMapper.php index a82fc4a..2144ccd 100644 --- a/src/Mapper/PartnerApiToEntityMapper.php +++ b/src/Mapper/PartnerApiToEntityMapper.php @@ -45,6 +45,7 @@ class PartnerApiToEntityMapper implements MapperInterface $entity = $to; assert($entity instanceof Partner); + $entity->setDescription($dto->description); $entity->setName($dto->name); $entity->setType($dto->partnerType); $entity->setStreet($dto->street); diff --git a/src/Mapper/PartnerEntityToApiMapper.php b/src/Mapper/PartnerEntityToApiMapper.php index c765502..a2d3403 100644 --- a/src/Mapper/PartnerEntityToApiMapper.php +++ b/src/Mapper/PartnerEntityToApiMapper.php @@ -43,6 +43,7 @@ class PartnerEntityToApiMapper implements MapperInterface $dto->name = $entity->getName(); $dto->partnerType = $entity->getType(); + $dto->description = $entity->getDescription(); $dto->street = $entity->getStreet(); $dto->streetNo = $entity->getStreetNo(); $dto->zip = $entity->getZip(); diff --git a/src/Mapper/SaleEntityToApiMapper.php b/src/Mapper/SaleEntityToApiMapper.php index e8efb9b..f4080b1 100644 --- a/src/Mapper/SaleEntityToApiMapper.php +++ b/src/Mapper/SaleEntityToApiMapper.php @@ -52,6 +52,7 @@ class SaleEntityToApiMapper implements MapperInterface MicroMapperInterface::MAX_DEPTH => 1, ]); $dto->partnerName = $entity->getPartner()?->getName(); + $dto->partnerType = $entity->getPartner()?->getType(); $dto->product = $this->microMapper->map($entity->getProduct(), ProductApi::class, [ MicroMapperInterface::MAX_DEPTH => 1,