| @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; | |||
| /** | |||
| * Auto-generated Migration: Please modify to your needs! | |||
| */ | |||
| final class Version20240216094550 extends AbstractMigration | |||
| final class Version20240304164555 extends AbstractMigration | |||
| { | |||
| public function getDescription(): string | |||
| { | |||
| @@ -29,8 +29,8 @@ final class Version20240216094550 extends AbstractMigration | |||
| $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)'); | |||
| $this->addSql('ALTER TABLE contact ADD CONSTRAINT FK_4C62E6389393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id)'); | |||
| $this->addSql('ALTER TABLE contact ADD CONSTRAINT FK_4C62E6383DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id)'); | |||
| $this->addSql('ALTER TABLE partner ADD CONSTRAINT FK_312B3E16F98F144A FOREIGN KEY (logo_id) REFERENCES media_object (id)'); | |||
| $this->addSql('ALTER TABLE contact ADD CONSTRAINT FK_4C62E6383DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL'); | |||
| $this->addSql('ALTER TABLE partner ADD CONSTRAINT FK_312B3E16F98F144A FOREIGN KEY (logo_id) REFERENCES media_object (id) ON DELETE SET NULL'); | |||
| $this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D737E3C61F9 FOREIGN KEY (owner_id) REFERENCES `user` (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)'); | |||
| @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; | |||
| use Doctrine\Common\Collections\Collection; | |||
| use Doctrine\DBAL\Types\Types; | |||
| use Doctrine\ORM\Mapping as ORM; | |||
| use Symfony\Component\Validator\Constraints as Assert; | |||
| #[ORM\Entity(repositoryClass: ContactRepository::class)] | |||
| class Contact | |||
| @@ -30,7 +31,7 @@ class Contact | |||
| private ?\DateTimeInterface $birthday = null; | |||
| #[ORM\ManyToOne(targetEntity: MediaObject::class)] | |||
| #[ORM\JoinColumn(nullable: true)] | |||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||
| private ?MediaObject $image = null; | |||
| #[ORM\Column(length: 255, nullable: true)] | |||
| @@ -101,6 +102,11 @@ class Contact | |||
| return $this->birthday; | |||
| } | |||
| public function getBirthdayAsString(): string | null | |||
| { | |||
| return $this->birthday?->format('Y-m-d'); | |||
| } | |||
| public function setBirthday(?\DateTimeInterface $birthday): static | |||
| { | |||
| $this->birthday = $birthday; | |||
| @@ -9,6 +9,7 @@ namespace App\Entity; | |||
| use ApiPlatform\Metadata\ApiProperty; | |||
| use ApiPlatform\Metadata\ApiResource; | |||
| use ApiPlatform\Metadata\Delete; | |||
| use ApiPlatform\Metadata\Get; | |||
| use ApiPlatform\Metadata\GetCollection; | |||
| use ApiPlatform\Metadata\Post; | |||
| @@ -49,7 +50,10 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich; | |||
| ), | |||
| validationContext: ['groups' => ['Default', 'media_object_create']], | |||
| deserialize: false | |||
| ) | |||
| ), | |||
| new Delete( | |||
| // controller: DeleteMediaObjectAction::class | |||
| ), | |||
| ], | |||
| normalizationContext: ['groups' => ['media_object:read']] | |||
| )] | |||
| @@ -47,7 +47,7 @@ class Partner | |||
| private Collection $contacts; | |||
| #[ORM\ManyToOne(targetEntity: MediaObject::class)] | |||
| #[ORM\JoinColumn(nullable: true)] | |||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||
| private ?MediaObject $logo = null; | |||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Posting::class, orphanRemoval: true)] | |||
| @@ -47,7 +47,7 @@ class ContactEntityToApiMapper implements MapperInterface | |||
| MicroMapperInterface::MAX_DEPTH => 1, | |||
| ] | |||
| ); | |||
| $dto->birthday = $entity->getBirthday(); | |||
| $dto->birthday = $entity->getBirthdayAsString(); | |||
| $dto->image = $entity->getImage(); | |||
| $dto->imageUrl = $this->fileUrlService->getFileUrl($entity->getImage()); | |||
| $dto->position = $entity->getPosition(); | |||
| @@ -78,5 +78,14 @@ class ContactResourceTest extends KernelTestCase | |||
| ->assertJsonMatches('"hydra:totalItems"', 1) | |||
| ->assertJsonMatches('"hydra:member"[0].position', 'CEO') | |||
| ; | |||
| $this->browser() | |||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||
| 'headers' => [ | |||
| 'Authorization' => 'Bearer ' . $token, | |||
| ], | |||
| ]) | |||
| ->assertSuccessful() | |||
| ; | |||
| } | |||
| } | |||
| @@ -7,6 +7,8 @@ | |||
| namespace App\Tests\Functional; | |||
| use App\Factory\MediaObjectLogoFactory; | |||
| use App\Factory\PartnerFactory; | |||
| use App\Factory\UserFactory; | |||
| use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | |||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | |||
| @@ -62,5 +64,51 @@ class MediaObjectResourceTest extends KernelTestCase | |||
| ]) | |||
| ->assertSuccessful() | |||
| ; | |||
| $partner = PartnerFactory::createOne(); | |||
| $this->browser() | |||
| ->patch('/api/partner/' . $partner->getId(), [ | |||
| 'headers' => [ | |||
| 'Authorization' => 'Bearer ' . $token, | |||
| ], | |||
| 'json' => [ | |||
| 'logo' => '/api/medias/1' | |||
| ] | |||
| ]) | |||
| ->assertSuccessful() | |||
| ; | |||
| $this->browser() | |||
| ->delete('/api/medias/1', [ | |||
| 'headers' => [ | |||
| 'Authorization' => 'Bearer ' . $token, | |||
| 'Content-Type' => 'multipart/form-data' | |||
| ], | |||
| ]) | |||
| ->assertSuccessful() | |||
| ; | |||
| } | |||
| public function testDeleteMediaObject() | |||
| { | |||
| $mediaObject = MediaObjectLogoFactory::createOne(); | |||
| $user = UserFactory::createOne( | |||
| [ | |||
| 'firstName' => 'Peter', | |||
| 'lastName' => 'Test', | |||
| 'password' => 'test', | |||
| 'email' => 'peter@test.de', | |||
| ] | |||
| ); | |||
| $token = $this->JWTManager->create($user->object()); | |||
| $this->browser() | |||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||
| 'headers' => [ | |||
| 'Authorization' => 'Bearer ' . $token, | |||
| 'Content-Type' => 'multipart/form-data' | |||
| ], | |||
| ]) | |||
| ->assertSuccessful() | |||
| ; | |||
| } | |||
| } | |||
| @@ -44,7 +44,7 @@ class PartnerResourceTest extends KernelTestCase | |||
| $mediaObject = MediaObjectLogoFactory::createOne(); | |||
| $token = $this->JWTManager->create($user->object()); | |||
| $this->browser() | |||
| $response = $this->browser() | |||
| ->post('/api/partners' , [ | |||
| 'json' => [ | |||
| 'name' => 'test customer', | |||
| @@ -63,6 +63,7 @@ class PartnerResourceTest extends KernelTestCase | |||
| ] | |||
| ]) | |||
| ->assertSuccessful() | |||
| ->content() | |||
| ; | |||
| $this->browser() | |||
| @@ -74,6 +75,16 @@ class PartnerResourceTest extends KernelTestCase | |||
| ->assertSuccessful() | |||
| ->assertJsonMatches('"hydra:totalItems"', 1) | |||
| ->assertJsonMatches('"hydra:member"[0].name', 'test customer') | |||
| ->content() | |||
| ; | |||
| $this->browser() | |||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||
| 'headers' => [ | |||
| 'Authorization' => 'Bearer ' . $token, | |||
| ], | |||
| ]) | |||
| ->assertSuccessful() | |||
| ; | |||
| } | |||
| } | |||