-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new files related to AssetFile creation and routing This update introduces new DTOs for handling the creation, validation, and routing of AssetFiles. These new additions, including `AssetFileSysCreateDto` and `AssetFileController.php`, facilitate asset creation and routing in the system. The included access control rules ensure authorized access to these functionalities. * Add ExtStorage configuration key and asset handling Integrated the 'ext_storage' configuration key into ExtSystemConfiguration to facilitate external storage in asset handling. Additional error handling mechanisms have also been implemented in the AssetFileController, AssetSysFacade, and AssetSysFactory to ensure data validity and reliability. Added validations for the newly created AssetFile. * Replace getClient with getApiClient in test cases fix tests
- Loading branch information
1 parent
fa21690
commit d5fb1d6
Showing
29 changed files
with
339 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Controller\Api\Sys\V1; | ||
|
||
use AnzuSystems\CommonBundle\Exception\ValidationException; | ||
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponse; | ||
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponseCreated; | ||
use AnzuSystems\CommonBundle\Model\OpenApi\Response\OAResponseValidation; | ||
use AnzuSystems\CoreDamBundle\Controller\Api\AbstractApiController; | ||
use AnzuSystems\CoreDamBundle\Domain\Asset\AssetSysFacade; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetFile; | ||
use AnzuSystems\CoreDamBundle\Exception\InvalidMimeTypeException; | ||
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AssetFileSysCreateDto; | ||
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AssetFileSysDetailDecorator; | ||
use AnzuSystems\CoreDamBundle\Security\Permission\DamPermissions; | ||
use AnzuSystems\SerializerBundle\Attributes\SerializeParam; | ||
use Doctrine\ORM\NonUniqueResultException; | ||
use League\Flysystem\FilesystemException; | ||
use OpenApi\Attributes as OA; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
#[OA\Tag('AssetFile')] | ||
#[Route('/asset-file', 'sys_asset_file_')] | ||
final class AssetFileController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
private readonly AssetSysFacade $assetSysFacade | ||
) { | ||
} | ||
|
||
/** | ||
* @throws FilesystemException | ||
* @throws ValidationException | ||
* @throws InvalidMimeTypeException | ||
* @throws NonUniqueResultException | ||
*/ | ||
#[Route('', 'create', methods: [Request::METHOD_POST])] | ||
#[OAResponse(AssetFileSysDetailDecorator::class), OAResponseValidation, OAResponseCreated] | ||
public function create(#[SerializeParam] AssetFileSysCreateDto $dto): JsonResponse | ||
{ | ||
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_CREATE, $dto); | ||
|
||
return $this->okResponse( | ||
AssetFileSysDetailDecorator::getInstance($this->assetSysFacade->createFromDto($dto)) | ||
); | ||
} | ||
|
||
#[Route('/{assetFile}', 'get_one', methods: [Request::METHOD_GET])] | ||
#[OAResponse(AssetFileSysDetailDecorator::class)] | ||
public function getOne(AssetFile $assetFile): JsonResponse | ||
{ | ||
$this->denyAccessUnlessGranted(DamPermissions::DAM_ASSET_VIEW, $assetFile->getAsset()); | ||
|
||
return $this->okResponse( | ||
AssetFileSysDetailDecorator::getInstance($assetFile) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Domain\Asset; | ||
|
||
use AnzuSystems\CommonBundle\Exception\ValidationException; | ||
use AnzuSystems\CommonBundle\Validator\Validator; | ||
use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileManagerProvider; | ||
use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileMessageDispatcher; | ||
use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileStatusFacadeProvider; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetFile; | ||
use AnzuSystems\CoreDamBundle\Exception\InvalidMimeTypeException; | ||
use AnzuSystems\CoreDamBundle\FileSystem\FileSystemProvider; | ||
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AssetFileSysCreateDto; | ||
use AnzuSystems\CoreDamBundle\Traits\IndexManagerAwareTrait; | ||
use Doctrine\ORM\NonUniqueResultException; | ||
use League\Flysystem\FilesystemException; | ||
|
||
final class AssetSysFacade | ||
{ | ||
use IndexManagerAwareTrait; | ||
|
||
public function __construct( | ||
private readonly Validator $validator, | ||
private readonly AssetSysFactory $assetSysFactory, | ||
private readonly AssetFileManagerProvider $assetFileManagerProvider, | ||
private readonly AssetFileMessageDispatcher $assetFileMessageDispatcher, | ||
private readonly AssetFileStatusFacadeProvider $facadeProvider, | ||
private readonly FileSystemProvider $fileSystemProvider, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws FilesystemException | ||
* @throws ValidationException | ||
* @throws InvalidMimeTypeException | ||
* @throws NonUniqueResultException | ||
*/ | ||
public function createFromDto(AssetFileSysCreateDto $dto): AssetFile | ||
{ | ||
$this->validator->validate($dto); | ||
$assetFile = $this->assetSysFactory->createFromDto($dto); | ||
$this->facadeProvider->getStatusFacade($assetFile)->storeAndProcess($assetFile); | ||
$this->fileSystemProvider->getTmpFileSystem()->clearPaths(); | ||
|
||
return $assetFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Domain\Asset; | ||
|
||
use AnzuSystems\CoreDamBundle\Domain\AssetFile\AssetFileFactory; | ||
use AnzuSystems\CoreDamBundle\Domain\Configuration\ExtSystemConfigurationProvider; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetFile; | ||
use AnzuSystems\CoreDamBundle\Exception\InvalidMimeTypeException; | ||
use AnzuSystems\CoreDamBundle\Model\Dto\AssetFile\AssetFileSysCreateDto; | ||
use Doctrine\ORM\NonUniqueResultException; | ||
use League\Flysystem\FilesystemException; | ||
|
||
final readonly class AssetSysFactory | ||
{ | ||
public function __construct( | ||
private AssetFileFactory $assetFileFactory, | ||
private ExtSystemConfigurationProvider $configurationProvider, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws FilesystemException | ||
* @throws NonUniqueResultException | ||
* @throws InvalidMimeTypeException | ||
*/ | ||
public function createFromDto(AssetFileSysCreateDto $dto): AssetFile | ||
{ | ||
$configuration = $this->configurationProvider->getExtSystemConfiguration($dto->getExtSystem()->getSlug()); | ||
|
||
return $this->assetFileFactory->createAssetFileForStorage( | ||
storageName: $configuration->getExtStorage(), | ||
filePath: $dto->getPath(), | ||
licence: $dto->getLicence() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Model\Dto\AssetFile; | ||
|
||
use AnzuSystems\CommonBundle\Exception\ValidationException; | ||
use AnzuSystems\CoreDamBundle\Entity\AssetLicence; | ||
use AnzuSystems\CoreDamBundle\Entity\ExtSystem; | ||
use AnzuSystems\CoreDamBundle\Entity\Interfaces\ExtSystemInterface; | ||
use AnzuSystems\SerializerBundle\Attributes\Serialize; | ||
use AnzuSystems\SerializerBundle\Handler\Handlers\EntityIdHandler; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
final class AssetFileSysCreateDto implements ExtSystemInterface | ||
{ | ||
#[Serialize] | ||
#[Assert\NotBlank(message: ValidationException::ERROR_FIELD_EMPTY)] | ||
#[Assert\Length(max: 192, maxMessage: ValidationException::ERROR_FIELD_LENGTH_MAX)] | ||
private string $path; | ||
|
||
#[Serialize(handler: EntityIdHandler::class)] | ||
#[Assert\NotBlank(message: ValidationException::ERROR_FIELD_EMPTY)] | ||
private AssetLicence $licence; | ||
|
||
public function getPath(): string | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function setPath(string $path): self | ||
{ | ||
$this->path = $path; | ||
return $this; | ||
} | ||
|
||
public function getLicence(): AssetLicence | ||
{ | ||
return $this->licence; | ||
} | ||
|
||
public function setLicence(AssetLicence $licence): self | ||
{ | ||
$this->licence = $licence; | ||
return $this; | ||
} | ||
|
||
public function getExtSystem(): ExtSystem | ||
{ | ||
return $this->licence->getExtSystem(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AnzuSystems\CoreDamBundle\Model\Dto\AssetFile; | ||
|
||
use AnzuSystems\CoreDamBundle\Entity\AssetFile; | ||
use AnzuSystems\CoreDamBundle\Model\Dto\AbstractEntityDto; | ||
use AnzuSystems\CoreDamBundle\Model\Enum\AssetFileProcessStatus; | ||
use AnzuSystems\CoreDamBundle\Model\Enum\AssetType; | ||
use AnzuSystems\SerializerBundle\Attributes\Serialize; | ||
|
||
final class AssetFileSysDetailDecorator extends AbstractEntityDto | ||
{ | ||
private AssetFile $assetFile; | ||
|
||
public static function getInstance(AssetFile $assetFile): static | ||
{ | ||
return self::getBaseInstance($assetFile) | ||
->setAssetFile($assetFile); | ||
} | ||
|
||
public function getAssetFile(): AssetFile | ||
{ | ||
return $this->assetFile; | ||
} | ||
|
||
public function setAssetFile(AssetFile $assetFile): self | ||
{ | ||
$this->assetFile = $assetFile; | ||
return $this; | ||
} | ||
|
||
#[Serialize] | ||
public function getOriginAssetFileId(): string | ||
{ | ||
return $this->assetFile->getAssetAttributes()->getOriginAssetId(); | ||
} | ||
|
||
|
||
#[Serialize] | ||
public function getAssetFileStatus(): AssetFileProcessStatus | ||
{ | ||
return $this->assetFile->getAssetAttributes()->getStatus(); | ||
} | ||
|
||
#[Serialize] | ||
public function getAssetId(): ?string | ||
{ | ||
return $this->assetFile->getAsset()->getId(); | ||
} | ||
|
||
#[Serialize] | ||
public function getAssetType(): AssetType | ||
{ | ||
return $this->assetFile->getAssetType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.