| @@ -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 Version20240216094550 extends AbstractMigration | |||||
| final class Version20240304164555 extends AbstractMigration | |||||
| { | { | ||||
| public function getDescription(): string | 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_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 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_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_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_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)'); | ||||
| @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; | |||||
| use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\DBAL\Types\Types; | use Doctrine\DBAL\Types\Types; | ||||
| use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
| use Symfony\Component\Validator\Constraints as Assert; | |||||
| #[ORM\Entity(repositoryClass: ContactRepository::class)] | #[ORM\Entity(repositoryClass: ContactRepository::class)] | ||||
| class Contact | class Contact | ||||
| @@ -30,7 +31,7 @@ class Contact | |||||
| private ?\DateTimeInterface $birthday = null; | private ?\DateTimeInterface $birthday = null; | ||||
| #[ORM\ManyToOne(targetEntity: MediaObject::class)] | #[ORM\ManyToOne(targetEntity: MediaObject::class)] | ||||
| #[ORM\JoinColumn(nullable: true)] | |||||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||||
| private ?MediaObject $image = null; | private ?MediaObject $image = null; | ||||
| #[ORM\Column(length: 255, nullable: true)] | #[ORM\Column(length: 255, nullable: true)] | ||||
| @@ -101,6 +102,11 @@ class Contact | |||||
| return $this->birthday; | return $this->birthday; | ||||
| } | } | ||||
| public function getBirthdayAsString(): string | null | |||||
| { | |||||
| return $this->birthday?->format('Y-m-d'); | |||||
| } | |||||
| public function setBirthday(?\DateTimeInterface $birthday): static | public function setBirthday(?\DateTimeInterface $birthday): static | ||||
| { | { | ||||
| $this->birthday = $birthday; | $this->birthday = $birthday; | ||||
| @@ -9,6 +9,7 @@ namespace App\Entity; | |||||
| use ApiPlatform\Metadata\ApiProperty; | use ApiPlatform\Metadata\ApiProperty; | ||||
| use ApiPlatform\Metadata\ApiResource; | use ApiPlatform\Metadata\ApiResource; | ||||
| use ApiPlatform\Metadata\Delete; | |||||
| use ApiPlatform\Metadata\Get; | use ApiPlatform\Metadata\Get; | ||||
| use ApiPlatform\Metadata\GetCollection; | use ApiPlatform\Metadata\GetCollection; | ||||
| use ApiPlatform\Metadata\Post; | use ApiPlatform\Metadata\Post; | ||||
| @@ -49,7 +50,10 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich; | |||||
| ), | ), | ||||
| validationContext: ['groups' => ['Default', 'media_object_create']], | validationContext: ['groups' => ['Default', 'media_object_create']], | ||||
| deserialize: false | deserialize: false | ||||
| ) | |||||
| ), | |||||
| new Delete( | |||||
| // controller: DeleteMediaObjectAction::class | |||||
| ), | |||||
| ], | ], | ||||
| normalizationContext: ['groups' => ['media_object:read']] | normalizationContext: ['groups' => ['media_object:read']] | ||||
| )] | )] | ||||
| @@ -47,7 +47,7 @@ class Partner | |||||
| private Collection $contacts; | private Collection $contacts; | ||||
| #[ORM\ManyToOne(targetEntity: MediaObject::class)] | #[ORM\ManyToOne(targetEntity: MediaObject::class)] | ||||
| #[ORM\JoinColumn(nullable: true)] | |||||
| #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")] | |||||
| private ?MediaObject $logo = null; | private ?MediaObject $logo = null; | ||||
| #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Posting::class, orphanRemoval: true)] | #[ORM\OneToMany(mappedBy: 'partner', targetEntity: Posting::class, orphanRemoval: true)] | ||||
| @@ -47,7 +47,7 @@ class ContactEntityToApiMapper implements MapperInterface | |||||
| MicroMapperInterface::MAX_DEPTH => 1, | MicroMapperInterface::MAX_DEPTH => 1, | ||||
| ] | ] | ||||
| ); | ); | ||||
| $dto->birthday = $entity->getBirthday(); | |||||
| $dto->birthday = $entity->getBirthdayAsString(); | |||||
| $dto->image = $entity->getImage(); | $dto->image = $entity->getImage(); | ||||
| $dto->imageUrl = $this->fileUrlService->getFileUrl($entity->getImage()); | $dto->imageUrl = $this->fileUrlService->getFileUrl($entity->getImage()); | ||||
| $dto->position = $entity->getPosition(); | $dto->position = $entity->getPosition(); | ||||
| @@ -78,5 +78,14 @@ class ContactResourceTest extends KernelTestCase | |||||
| ->assertJsonMatches('"hydra:totalItems"', 1) | ->assertJsonMatches('"hydra:totalItems"', 1) | ||||
| ->assertJsonMatches('"hydra:member"[0].position', 'CEO') | ->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; | namespace App\Tests\Functional; | ||||
| use App\Factory\MediaObjectLogoFactory; | |||||
| use App\Factory\PartnerFactory; | |||||
| use App\Factory\UserFactory; | use App\Factory\UserFactory; | ||||
| use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | ||||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||||
| @@ -62,5 +64,51 @@ class MediaObjectResourceTest extends KernelTestCase | |||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->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(); | $mediaObject = MediaObjectLogoFactory::createOne(); | ||||
| $token = $this->JWTManager->create($user->object()); | $token = $this->JWTManager->create($user->object()); | ||||
| $this->browser() | |||||
| $response = $this->browser() | |||||
| ->post('/api/partners' , [ | ->post('/api/partners' , [ | ||||
| 'json' => [ | 'json' => [ | ||||
| 'name' => 'test customer', | 'name' => 'test customer', | ||||
| @@ -63,6 +63,7 @@ class PartnerResourceTest extends KernelTestCase | |||||
| ] | ] | ||||
| ]) | ]) | ||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| ->content() | |||||
| ; | ; | ||||
| $this->browser() | $this->browser() | ||||
| @@ -74,6 +75,16 @@ class PartnerResourceTest extends KernelTestCase | |||||
| ->assertSuccessful() | ->assertSuccessful() | ||||
| ->assertJsonMatches('"hydra:totalItems"', 1) | ->assertJsonMatches('"hydra:totalItems"', 1) | ||||
| ->assertJsonMatches('"hydra:member"[0].name', 'test customer') | ->assertJsonMatches('"hydra:member"[0].name', 'test customer') | ||||
| ->content() | |||||
| ; | |||||
| $this->browser() | |||||
| ->delete('/api/medias/' . $mediaObject->getId(), [ | |||||
| 'headers' => [ | |||||
| 'Authorization' => 'Bearer ' . $token, | |||||
| ], | |||||
| ]) | |||||
| ->assertSuccessful() | |||||
| ; | ; | ||||
| } | } | ||||
| } | } | ||||