diff --git a/config/services.yaml b/config/services.yaml index ef0ae7b..a71484f 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -29,8 +29,8 @@ services: - { name: kernel.event_listener, event: lexik_jwt_authentication.on_authentication_success, method: onAuthenticationSuccessResponse } arguments: ['@symfonycasts.micro_mapper', '@api_platform.iri_converter'] - App\Serializer\MediaObjectNormalizer: - arguments: - $storage: '@vich_uploader.storage.file_system' - tags: - - { name: 'api_platform.jsonld.normalizer.item', priority: 1000 } \ No newline at end of file +# App\Serializer\MediaObjectNormalizer: +# arguments: +# $storage: '@vich_uploader.storage.file_system' +# tags: +# - { name: 'api_platform.jsonld.normalizer.item', priority: 1000 } \ No newline at end of file diff --git a/migrations/Version20240207141851.php b/migrations/Version20240213115154.php similarity index 92% rename from migrations/Version20240207141851.php rename to migrations/Version20240213115154.php index 203cf53..2849d9d 100644 --- a/migrations/Version20240207141851.php +++ b/migrations/Version20240213115154.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240207141851 extends AbstractMigration +final class Version20240213115154 extends AbstractMigration { public function getDescription(): string { @@ -21,7 +21,7 @@ final class Version20240207141851 extends AbstractMigration { // this up() migration is auto-generated, please modify it to your needs $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 DATE DEFAULT NULL, 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 media_object (id INT AUTO_INCREMENT NOT NULL, file_path VARCHAR(255) DEFAULT NULL, 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 posting (id INT AUTO_INCREMENT NOT NULL, owner_id INT NOT NULL, message LONGTEXT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_BD275D737E3C61F9 (owner_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, 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), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); diff --git a/src/Entity/MediaObject.php b/src/Entity/MediaObject.php index fed44a2..bb0ff2a 100644 --- a/src/Entity/MediaObject.php +++ b/src/Entity/MediaObject.php @@ -68,8 +68,37 @@ class MediaObject #[ORM\Column(nullable: true)] public ?string $filePath = null; + #[ORM\Column] + private ?\DateTimeImmutable $createdAt = null; + + public function __construct() + { + $this->createdAt = new \DateTimeImmutable(); + } + public function getId(): ?int { return $this->id; } + + public function getContentUrl(): ?string + { + return $this->contentUrl; + } + + public function getFile(): ?File + { + return $this->file; + } + + public function getFilePath(): ?string + { + return $this->filePath; + } + + public function getCreatedAt(): ?\DateTimeImmutable + { + return $this->createdAt; + } + } \ No newline at end of file diff --git a/src/Serializer/MediaObjectNormalizer.php b/src/Serializer/MediaObjectNormalizer.php index effc595..7cf46fb 100644 --- a/src/Serializer/MediaObjectNormalizer.php +++ b/src/Serializer/MediaObjectNormalizer.php @@ -15,6 +15,7 @@ use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerInterface; use Vich\UploaderBundle\Storage\StorageInterface; +//final class MediaObjectNormalizer #[AsDecorator('api_platform.jsonld.normalizer.item')] final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwareInterface { @@ -31,7 +32,10 @@ final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwar { $context[self::ALREADY_CALLED] = true; - $object->contentUrl = $this->storage->resolveUri($object, 'file'); + if ($object instanceof MediaObject) { + // Nur für MediaObject die URI generieren + $object->contentUrl = $this->storage->resolveUri($object, 'file'); + } return $this->normalizer->normalize($object, $format, $context); } @@ -42,7 +46,7 @@ final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwar return false; } - return $data instanceof MediaObject; + return $this->normalizer->supportsNormalization($data, $format, $context); } public function setSerializer(SerializerInterface $serializer): void