| @@ -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 Version20240305164344 extends AbstractMigration | |||||
| final class Version20240308161707 extends AbstractMigration | |||||
| { | { | ||||
| public function getDescription(): string | public function getDescription(): string | ||||
| { | { | ||||
| @@ -36,7 +36,7 @@ final class Version20240305164344 extends AbstractMigration | |||||
| $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D739393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id)'); | $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D739393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id)'); | ||||
| $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D73E7A1254A FOREIGN KEY (contact_id) REFERENCES contact (id)'); | $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D73E7A1254A FOREIGN KEY (contact_id) REFERENCES contact (id)'); | ||||
| $this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD3DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL'); | $this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD3DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL'); | ||||
| $this->addSql('ALTER TABLE `user` ADD CONSTRAINT FK_8D93D6493DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id)'); | |||||
| $this->addSql('ALTER TABLE `user` ADD CONSTRAINT FK_8D93D6493DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL'); | |||||
| } | } | ||||
| public function down(Schema $schema): void | public function down(Schema $schema): void | ||||
| @@ -79,6 +79,7 @@ class PartnerApi | |||||
| #[ApiProperty(writable: false)] | #[ApiProperty(writable: false)] | ||||
| public ?string $logoUrl = null; | public ?string $logoUrl = null; | ||||
| #[ApiProperty(writable: false)] | |||||
| public ?\DateTimeImmutable $createdAt = null; | public ?\DateTimeImmutable $createdAt = null; | ||||
| /** | /** | ||||
| @@ -14,6 +14,7 @@ use ApiPlatform\Metadata\Get; | |||||
| use ApiPlatform\Metadata\GetCollection; | use ApiPlatform\Metadata\GetCollection; | ||||
| use ApiPlatform\Metadata\Patch; | use ApiPlatform\Metadata\Patch; | ||||
| use ApiPlatform\Metadata\Post; | use ApiPlatform\Metadata\Post; | ||||
| use App\Entity\MediaObject; | |||||
| use App\Entity\User; | use App\Entity\User; | ||||
| use App\State\EntityClassDtoStateProcessor; | use App\State\EntityClassDtoStateProcessor; | ||||
| use App\State\EntityToDtoStateProvider; | use App\State\EntityToDtoStateProvider; | ||||
| @@ -57,6 +58,8 @@ class UserApi | |||||
| #[Assert\NotBlank] | #[Assert\NotBlank] | ||||
| public ?string $lastName = null; | public ?string $lastName = null; | ||||
| public ?MediaObject $image = null; | |||||
| /** | /** | ||||
| * The plaintext password when being set or changed. | * The plaintext password when being set or changed. | ||||
| */ | */ | ||||
| @@ -27,7 +27,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface | |||||
| #[ORM\Column(length: 255)] | #[ORM\Column(length: 255)] | ||||
| private ?string $lastName = null; | private ?string $lastName = null; | ||||
| #[ORM\ManyToOne] | |||||
| #[ORM\ManyToOne(targetEntity: MediaObject::class)] | |||||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||||
| private ?MediaObject $image = null; | private ?MediaObject $image = null; | ||||
| #[ORM\Column] | #[ORM\Column] | ||||
| @@ -17,10 +17,10 @@ use Symfonycasts\MicroMapper\MicroMapperInterface; | |||||
| class UserApiToEntityMapper implements MapperInterface | class UserApiToEntityMapper implements MapperInterface | ||||
| { | { | ||||
| public function __construct( | public function __construct( | ||||
| private UserRepository $userRepository, | |||||
| private UserRepository $repository, | |||||
| private UserPasswordHasherInterface $userPasswordHasher, | private UserPasswordHasherInterface $userPasswordHasher, | ||||
| private MicroMapperInterface $microMapper, | |||||
| private PropertyAccessorInterface $propertyAccessor, | |||||
| private MicroMapperInterface $microMapper, | |||||
| private PropertyAccessorInterface $propertyAccessor, | |||||
| ) | ) | ||||
| { | { | ||||
| } | } | ||||
| @@ -30,12 +30,12 @@ class UserApiToEntityMapper implements MapperInterface | |||||
| $dto = $from; | $dto = $from; | ||||
| assert($dto instanceof UserApi); | assert($dto instanceof UserApi); | ||||
| $userEntity = $dto->id ? $this->userRepository->find($dto->id) : new User(); | |||||
| if (!$userEntity) { | |||||
| $entity = $dto->id ? $this->repository->find($dto->id) : new User(); | |||||
| if (!$entity) { | |||||
| throw new \Exception('User not found'); | throw new \Exception('User not found'); | ||||
| } | } | ||||
| return $userEntity; | |||||
| return $entity; | |||||
| } | } | ||||
| public function populate(object $from, object $to, array $context): object | public function populate(object $from, object $to, array $context): object | ||||
| @@ -53,11 +53,6 @@ class UserApiToEntityMapper implements MapperInterface | |||||
| } | } | ||||
| $userPostsEntities = new ArrayCollection(); | $userPostsEntities = new ArrayCollection(); | ||||
| foreach ($dto->posts as $userPostApi) { | |||||
| $userPostsEntities[] = $this->microMapper->map($userPostApi, Posting::class, [ | |||||
| MicroMapperInterface::MAX_DEPTH => 1, | |||||
| ]); | |||||
| } | |||||
| $this->propertyAccessor->setValue($entity, 'postings', $userPostsEntities); | $this->propertyAccessor->setValue($entity, 'postings', $userPostsEntities); | ||||
| return $entity; | return $entity; | ||||
| @@ -40,6 +40,7 @@ class UserEntityToApiMapper implements MapperInterface | |||||
| $dto->email = $entity->getEmail(); | $dto->email = $entity->getEmail(); | ||||
| $dto->firstName = $entity->getFirstName(); | $dto->firstName = $entity->getFirstName(); | ||||
| $dto->lastName = $entity->getLastName(); | $dto->lastName = $entity->getLastName(); | ||||
| $dto->image = $entity->getImage(); | |||||
| return $dto; | return $dto; | ||||
| } | } | ||||
| @@ -44,7 +44,7 @@ final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwar | |||||
| if (isset($context[self::ALREADY_CALLED])) { | if (isset($context[self::ALREADY_CALLED])) { | ||||
| //return false; | //return false; | ||||
| } | } | ||||
| // return $data instanceof MediaObject; | |||||
| return $this->normalizer->supportsNormalization($data, $format, $context); | return $this->normalizer->supportsNormalization($data, $format, $context); | ||||
| } | } | ||||
| @@ -82,7 +82,6 @@ class CommentResourceTest extends KernelTestCase | |||||
| ], | ], | ||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| ->dd() | |||||
| ; | ; | ||||
| } | } | ||||
| } | } | ||||
| @@ -56,7 +56,7 @@ class ContactResourceTest extends KernelTestCase | |||||
| 'lastName' => 'Test', | 'lastName' => 'Test', | ||||
| 'partner' => '/api/partners/' . $partner->getId(), | 'partner' => '/api/partners/' . $partner->getId(), | ||||
| 'birthday' => '1984-02-10', | 'birthday' => '1984-02-10', | ||||
| 'image' => '/api/media/' . $mediaObject->getId(), | |||||
| 'image' => '/api/medias/' . $mediaObject->getId(), | |||||
| 'position' => 'CEO', | 'position' => 'CEO', | ||||
| 'phone' => '123456789', | 'phone' => '123456789', | ||||
| 'email' => 'peter@test2.de', | 'email' => 'peter@test2.de', | ||||
| @@ -80,7 +80,7 @@ class ContactResourceTest extends KernelTestCase | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/media/' . $mediaObject->getId(), [ | |||||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -53,7 +53,16 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| $token = $this->JWTManager->create($user->object()); | $token = $this->JWTManager->create($user->object()); | ||||
| $this->browser() | $this->browser() | ||||
| ->post('/api/media', [ | |||||
| ->get('/api/medias', [ | |||||
| 'headers' => [ | |||||
| 'Authorization' => 'Bearer ' . $token, | |||||
| ], | |||||
| ]) | |||||
| ->assertSuccessful() | |||||
| ; | |||||
| $this->browser() | |||||
| ->post('/api/medias', [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| 'Content-Type' => 'multipart/form-data' | 'Content-Type' => 'multipart/form-data' | ||||
| @@ -67,22 +76,24 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| $partner = PartnerFactory::createOne(); | $partner = PartnerFactory::createOne(); | ||||
| $this->browser() | $this->browser() | ||||
| ->patch('/api/partner/' . $partner->getId(), [ | |||||
| ->patch('/api/partners/' . $partner->getId(), | |||||
| [ | |||||
| 'json' => [ | |||||
| 'logo' => '/api/medias/1' | |||||
| ], | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| 'Content-Type' => 'application/merge-patch+json' | |||||
| ], | ], | ||||
| 'json' => [ | |||||
| 'logo' => '/api/media/1' | |||||
| ] | |||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/media/1', [ | |||||
| ->delete('/api/medias/1', | |||||
| [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| 'Content-Type' => 'multipart/form-data' | |||||
| ], | ], | ||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| @@ -102,10 +113,9 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| ); | ); | ||||
| $token = $this->JWTManager->create($user->object()); | $token = $this->JWTManager->create($user->object()); | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/media/' . $mediaObject->getId(), [ | |||||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| 'Content-Type' => 'multipart/form-data' | |||||
| ], | ], | ||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| @@ -55,7 +55,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/media/' . $mediaObject->getId(), | |||||
| 'logo' => '/api/medias/' . $mediaObject->getId(), | |||||
| ], | ], | ||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| @@ -79,7 +79,7 @@ class PartnerResourceTest extends KernelTestCase | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| ->delete('/api/media/' . $mediaObject->getId(), [ | |||||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||
| ], | ], | ||||
| @@ -54,7 +54,7 @@ class ProductResourceTest extends KernelTestCase | |||||
| 'json' => [ | 'json' => [ | ||||
| 'name' => 'Test', | 'name' => 'Test', | ||||
| 'description' => 'more test', | 'description' => 'more test', | ||||
| 'image' => '/api/media/' . $mediaObject->getId(), | |||||
| 'image' => '/api/medias/' . $mediaObject->getId(), | |||||
| ], | ], | ||||
| 'headers' => [ | 'headers' => [ | ||||
| 'Authorization' => 'Bearer ' . $token, | 'Authorization' => 'Bearer ' . $token, | ||||