| @@ -1,29 +0,0 @@ | |||||
| <?php | |||||
| /** | |||||
| * @author Daniel Knudsen <d.knudsen@spawntree.de> | |||||
| * @date 25.01.24 | |||||
| */ | |||||
| namespace App\Controller; | |||||
| use App\Entity\MediaObject; | |||||
| use Doctrine\ORM\EntityManagerInterface; | |||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||||
| use Symfony\Component\HttpKernel\Attribute\AsController; | |||||
| #[AsController] | |||||
| final class DeleteMediaObjectAction extends AbstractController | |||||
| { | |||||
| public function __invoke( | |||||
| MediaObject $mediaObject, | |||||
| EntityManagerInterface $em, | |||||
| ): null | |||||
| { | |||||
| $em->remove($mediaObject); | |||||
| $em->flush(); | |||||
| return null; | |||||
| } | |||||
| } | |||||
| @@ -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 | ||||
| @@ -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; | ||||
| @@ -15,7 +15,6 @@ use ApiPlatform\Metadata\GetCollection; | |||||
| use ApiPlatform\Metadata\Post; | use ApiPlatform\Metadata\Post; | ||||
| use ApiPlatform\OpenApi\Model; | use ApiPlatform\OpenApi\Model; | ||||
| use App\Controller\CreateMediaObjectAction; | use App\Controller\CreateMediaObjectAction; | ||||
| use App\Controller\DeleteMediaObjectAction; | |||||
| use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
| use Symfony\Component\HttpFoundation\File\File; | use Symfony\Component\HttpFoundation\File\File; | ||||
| use Symfony\Component\Serializer\Annotation\Groups; | use Symfony\Component\Serializer\Annotation\Groups; | ||||
| @@ -53,7 +52,7 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich; | |||||
| deserialize: false | deserialize: false | ||||
| ), | ), | ||||
| new Delete( | new Delete( | ||||
| controller: DeleteMediaObjectAction::class | |||||
| // controller: DeleteMediaObjectAction::class | |||||
| ), | ), | ||||
| ], | ], | ||||
| normalizationContext: ['groups' => ['media_object:read']] | normalizationContext: ['groups' => ['media_object:read']] | ||||
| @@ -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(); | ||||