Skip to content

Commit

Permalink
Refactor links serialization in response and add image animation support
Browse files Browse the repository at this point in the history
Deleted `AudioLinksHandler`, `ImageLinksHandler`, and `ImageLinksManyTagsHandler` and created a unified `LinksHandler` for processing audio and image link serialization. Image animation support was added in `ImageUrlFactory` and `ImageController`. To allow different configurations for views, introduced the `ApiViewType` enum that replaces hardcoded constant strings.
  • Loading branch information
TomasHermanek committed Jan 2, 2024
1 parent 49aff42 commit 6d3279f
Show file tree
Hide file tree
Showing 23 changed files with 299 additions and 338 deletions.
21 changes: 21 additions & 0 deletions src/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ public function __construct(
) {
}

#[Route(
path: '/animated/{imageId}.gif',
name: 'get_one_animated',
requirements: [
'imageId' => '[0-9a-zA-Z-]+',
],
methods: [Request::METHOD_GET]
)]
public function animation(
string $imageId,
): Response {
$image = $this->imageFileRepository->findProcessedById($imageId);

if (null === $image) {
// not found image with crop
return $this->notFoundResponse();
}

return $this->streamResponse($image);
}

/**
* @throws NonUniqueResultException
* @throws FilesystemException
Expand Down
11 changes: 11 additions & 0 deletions src/Domain/Image/ImageUrlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ public function __construct(
) {
}

public function generateAnimatedUrl(
string $imageId,
): string {
return $this->router->generate(
'image_get_one_animated',
[
'imageId' => $imageId,
]
);
}

public function generateAllowListUrl(
string $imageId,
CropAllowItem $item,
Expand Down
10 changes: 0 additions & 10 deletions src/Entity/AssetFileRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
use AnzuSystems\Contracts\Entity\Traits\TimeTrackingTrait;
use AnzuSystems\Contracts\Entity\Traits\UserTrackingTrait;
use AnzuSystems\CoreDamBundle\App;
use AnzuSystems\CoreDamBundle\Entity\Embeds\AudioAttributes;
use AnzuSystems\CoreDamBundle\Entity\Embeds\RouteUri;
use AnzuSystems\CoreDamBundle\Entity\Interfaces\FileSystemStorableInterface;
use AnzuSystems\CoreDamBundle\Entity\Traits\UuidIdentityTrait;
use AnzuSystems\CoreDamBundle\Model\Enum\AssetType;
use AnzuSystems\CoreDamBundle\Model\Enum\RouteMode;
use AnzuSystems\CoreDamBundle\Model\Enum\RouteStatus;
use AnzuSystems\CoreDamBundle\Repository\AssetFileRouteRepository;
use AnzuSystems\CoreDamBundle\Repository\AssetSlotRepository;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\AssetFileRouteLinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: AssetFileRouteRepository::class)]
Expand Down Expand Up @@ -100,12 +96,6 @@ public function setMode(RouteMode $mode): self
return $this;
}

#[Serialize(handler: AssetFileRouteLinksHandler::class)]
public function getLinks(): self
{
return $this;
}

public function getFilePath(): string
{
return $this->uri->getPath();
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/Podcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use AnzuSystems\CoreDamBundle\Entity\Interfaces\ImagePreviewableInterface;
use AnzuSystems\CoreDamBundle\Entity\Traits\UuidIdentityTrait;
use AnzuSystems\CoreDamBundle\Repository\PodcastRepository;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\LinksHandler;
use AnzuSystems\CoreDamBundle\Validator\Constraints as AppAssert;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler;
Expand Down Expand Up @@ -181,13 +181,13 @@ public function getExtSystem(): ExtSystem
return $this->licence->getExtSystem();
}

#[Serialize(handler: ImageLinksHandler::class, type: ImageLinksHandler::TAG_LIST)]
#[Serialize(handler: LinksHandler::class)]
public function getLinks(): ?AssetFile
{
return $this->getImagePreview()?->getImageFile();
}

#[Serialize(handler: ImageLinksHandler::class, type: ImageLinksHandler::TAG_LIST)]
#[Serialize(handler: LinksHandler::class)]
public function getAltLinks(): ?AssetFile
{
return $this->getAltImage()?->getImageFile();
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/PodcastEpisode.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use AnzuSystems\CoreDamBundle\Entity\Traits\UuidIdentityTrait;
use AnzuSystems\CoreDamBundle\Model\Enum\AssetType;
use AnzuSystems\CoreDamBundle\Repository\PodcastEpisodeRepository;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\LinksHandler;
use AnzuSystems\CoreDamBundle\Validator\Constraints as AppAssert;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler;
Expand Down Expand Up @@ -190,7 +190,7 @@ public function setFlags(PodcastEpisodeFlags $flags): self
return $this;
}

#[Serialize(handler: ImageLinksHandler::class, type: ImageLinksHandler::TAG_LIST)]
#[Serialize(handler: LinksHandler::class)]
public function getLinks(): ?AssetFile
{
return $this->getImagePreview()?->getImageFile();
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Dto/Asset/AssetAdmDetailDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use AnzuSystems\CoreDamBundle\Model\Dto\Asset\Embeds\AssetFlagsAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\Asset\Embeds\AssetTextsAdmListDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetMetadata\AssetMetadataAdmDetailDto;
use AnzuSystems\CoreDamBundle\Model\Enum\ApiViewType;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\AssetFileHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler;
use Doctrine\Common\Collections\Collection;
Expand Down Expand Up @@ -144,7 +144,7 @@ public function getDistributionCategory(): ?DistributionCategory
return $this->asset->getDistributionCategory();
}

#[Serialize(handler: AssetFileHandler::class, type: ImageLinksHandler::TAG_DETAIL)]
#[Serialize(handler: AssetFileHandler::class, type: ApiViewType::DETAIL)]
public function getMainFile(): ?AssetFile
{
return $this->asset->getMainFile();
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Dto/Asset/AssetAdmListDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use AnzuSystems\CoreDamBundle\Model\Dto\Asset\Embeds\AssetAttributesAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\Asset\Embeds\AssetFilePropertiesAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\Asset\Embeds\AssetTextsAdmListDto;
use AnzuSystems\CoreDamBundle\Model\Enum\ApiViewType;
use AnzuSystems\CoreDamBundle\Model\Enum\AssetType;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\AssetFileHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler;

Expand Down Expand Up @@ -50,7 +50,7 @@ public function setAsset(Asset $asset): static
return $this;
}

#[Serialize(handler: AssetFileHandler::class, type: ImageLinksHandler::TAG_LIST)]
#[Serialize(handler: AssetFileHandler::class, type: ApiViewType::LIST)]
public function getMainFile(): ?AssetFile
{
return $this->asset->getMainFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class AssetFileRouteAdmDetailDecorator extends AbstractEntityDto
private AssetFileRoute $assetFileRoute;

public static function getInstance(
AssetFileRoute $assetFileRoute
AssetFileRoute $assetFileRoute
): static {
return self::getBaseInstance($assetFileRoute)->setAssetFileRoute($assetFileRoute);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Dto/AssetSlot/AssetSlotAdmListDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use AnzuSystems\CoreDamBundle\Entity\AssetFile;
use AnzuSystems\CoreDamBundle\Entity\AssetSlot;
use AnzuSystems\CoreDamBundle\Model\Dto\AbstractEntityDto;
use AnzuSystems\CoreDamBundle\Model\Enum\ApiViewType;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\AssetFileHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;

class AssetSlotAdmListDecorator extends AbstractEntityDto
Expand Down Expand Up @@ -37,7 +37,7 @@ public function setAssetSlot(AssetSlot $assetSlot): self
return $this;
}

#[Serialize(handler: AssetFileHandler::class, type: ImageLinksHandler::TAG_DETAIL)]
#[Serialize(handler: AssetFileHandler::class, type: ApiViewType::DETAIL)]
public function getAssetFile(): AssetFile
{
return $this->assetSlot->getAssetFile();
Expand Down
7 changes: 0 additions & 7 deletions src/Model/Dto/Audio/AudioFileAdmDetailDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFileRoute\AssetFileRouteAdmDetailDecorator;
use AnzuSystems\CoreDamBundle\Model\Dto\Audio\Embeds\AudioAttributesAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\Audio\Embeds\AudioPublicLinkAdmDto;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\AudioLinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;

final class AudioFileAdmDetailDto extends AudioFileAdmListDto
Expand Down Expand Up @@ -51,12 +50,6 @@ public function setPublicLink(AudioPublicLinkAdmDto $publicLink): self
return $this;
}

#[Serialize(handler: AudioLinksHandler::class)]
public function getLinks(): AudioFile
{
return $this->audio;
}

#[Serialize]
public function getOriginAssetFile(): string
{
Expand Down
6 changes: 2 additions & 4 deletions src/Model/Dto/Audio/AudioFileAdmListDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

use AnzuSystems\CoreDamBundle\Entity\Asset;
use AnzuSystems\CoreDamBundle\Entity\AudioFile;
use AnzuSystems\CoreDamBundle\Model\Dto\AbstractEntityDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AbstractAssetFileAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\Embeds\AssetFileAttributesAdmDto;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\AudioLinksHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\LinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler;

Expand Down Expand Up @@ -47,7 +45,7 @@ public function getAsset(): Asset
return $this->audio->getAsset();
}

#[Serialize(handler: AudioLinksHandler::class)]
#[Serialize(handler: LinksHandler::class)]
public function getLinks(): AudioFile
{
return $this->audio;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Dto/Document/DocumentFileAdmDetailDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function getMainRoute(): ?AssetFileRouteAdmDetailDecorator
return $this->document->getMainRoute()
? AssetFileRouteAdmDetailDecorator::getInstance($this->document->getMainRoute())
: null
;
;
}
}
4 changes: 2 additions & 2 deletions src/Model/Dto/Image/ImageFileAdmDetailDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFileRoute\AssetFileRouteAdmDetailDecorator;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetMetadata\AssetMetadataAdmDetailDto;
use AnzuSystems\CoreDamBundle\Model\Dto\Image\Embeds\ImageAttributesAdmDto;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\LinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;

final class ImageFileAdmDetailDto extends ImageFileAdmListDto
Expand Down Expand Up @@ -79,7 +79,7 @@ public function setAssetMetadata(AssetMetadataAdmDetailDto $assetMetadata): self
return $this;
}

#[Serialize(handler: ImageLinksHandler::class, type: ImageLinksHandler::TAG_DETAIL)]
#[Serialize(handler: LinksHandler::class)]
public function getLinks(): ImageFile
{
return $this->image;
Expand Down
8 changes: 2 additions & 6 deletions src/Model/Dto/Image/ImageFileAdmListDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

namespace AnzuSystems\CoreDamBundle\Model\Dto\Image;

use AnzuSystems\CoreDamBundle\Entity\Asset;
use AnzuSystems\CoreDamBundle\Entity\ImageFile;
use AnzuSystems\CoreDamBundle\Model\Dto\AbstractEntityDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AbstractAssetFileAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\Embeds\AssetFileAttributesAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\Embeds\AssetFileFlagsAdmDto;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\LinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler;

Expand Down Expand Up @@ -42,7 +38,7 @@ public function setImage(ImageFile $image): self
return $this;
}

#[Serialize(handler: ImageLinksHandler::class, type: ImageLinksHandler::LIST_LINKS_TAGS)]
#[Serialize(handler: LinksHandler::class)]
public function getLinks(): ImageFile
{
return $this->image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use AnzuSystems\CommonBundle\Exception\ValidationException;
use AnzuSystems\CoreDamBundle\Entity\ImageFile;
use AnzuSystems\CoreDamBundle\Entity\RegionOfInterest;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksManyTagsHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\LinksTagCollectionHandler;
use AnzuSystems\CoreDamBundle\Validator\Constraints as AppAssert;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down Expand Up @@ -102,7 +101,7 @@ public function setPercentageHeight(float $percentageHeight): self
return $this;
}

#[Serialize(handler: ImageLinksManyTagsHandler::class, type: ImageLinksHandler::TAG_ROI_EXAMPLE)]
#[Serialize(handler: LinksTagCollectionHandler::class)]
public function getLinks(): ImageFile
{
return $this->image;
Expand Down
7 changes: 2 additions & 5 deletions src/Model/Dto/Video/VideoFileAdmListDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace AnzuSystems\CoreDamBundle\Model\Dto\Video;

use AnzuSystems\CoreDamBundle\Entity\Asset;
use AnzuSystems\CoreDamBundle\Entity\AssetFile;
use AnzuSystems\CoreDamBundle\Entity\ImagePreview;
use AnzuSystems\CoreDamBundle\Entity\VideoFile;
use AnzuSystems\CoreDamBundle\Model\Dto\AbstractEntityDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AbstractAssetFileAdmDto;
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\Embeds\AssetFileAttributesAdmDto;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\ImageLinksHandler;
use AnzuSystems\CoreDamBundle\Serializer\Handler\Handlers\LinksHandler;
use AnzuSystems\SerializerBundle\Attributes\Serialize;
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler;

Expand Down Expand Up @@ -49,7 +46,7 @@ public function setVideo(VideoFile $video): static
return $this;
}

#[Serialize(handler: ImageLinksHandler::class, type: ImageLinksHandler::LIST_LINKS_TAGS)]
#[Serialize(handler: LinksHandler::class)]
public function getLinks(): ?AssetFile
{
return $this->video->getImagePreview()?->getImageFile();
Expand Down
7 changes: 5 additions & 2 deletions src/Model/Enum/ApiViewType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ enum ApiViewType: string implements EnumInterface
{
use BaseEnumTrait;

case List = 'list';
case Detail = 'detail';
public const LIST = 'list';
public const DETAIL= 'detail';

case List = self::LIST;
case Detail = self::DETAIL;
}
Loading

0 comments on commit 6d3279f

Please sign in to comment.