refs #1472. Changes in images and imageRepo
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
dc68c8eb43
commit
28914fd7de
|
@ -16,6 +16,8 @@ resources:
|
|||
- 'api_platform.filter.image.order'
|
||||
- 'api_platform.filter.image.search'
|
||||
- 'api_platform.filter.image.boolean'
|
||||
- 'image.repository_filter'
|
||||
|
||||
ApiPlatform\Metadata\Get:
|
||||
provider: App\State\Provider\ImageProvider
|
||||
ApiPlatform\Metadata\Put:
|
||||
|
@ -77,6 +79,15 @@ resources:
|
|||
uriTemplate: /images/server/{uuid}/recover
|
||||
controller: App\Controller\OgRepository\Image\RecoverAction
|
||||
|
||||
transfer_image_ogrepository:
|
||||
shortName: OgRepository Server
|
||||
description: Export Image in OgRepository
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: App\Dto\Input\ExportImportImageRepositoryInput
|
||||
uriTemplate: /images/{uuid}/transfer-image
|
||||
controller: App\Controller\OgRepository\Image\TransferAction
|
||||
|
||||
properties:
|
||||
App\Entity\Image:
|
||||
id:
|
||||
|
|
|
@ -66,15 +66,6 @@ resources:
|
|||
uriTemplate: /image-repositories/{uuid}/export-image
|
||||
controller: App\Controller\OgRepository\Image\ExportAction
|
||||
|
||||
transfer_image_ogrepository:
|
||||
shortName: OgRepository Server
|
||||
description: Export Image in OgRepository
|
||||
class: ApiPlatform\Metadata\Post
|
||||
method: POST
|
||||
input: App\Dto\Input\ExportImportImageRepositoryInput
|
||||
uriTemplate: /image-repositories/{uuid}/transfer-image
|
||||
controller: App\Controller\OgRepository\Image\TransferAction
|
||||
|
||||
properties:
|
||||
App\Entity\ImageRepository:
|
||||
id:
|
||||
|
|
|
@ -69,6 +69,10 @@ services:
|
|||
arguments: [ { 'created': ~ } ]
|
||||
tags: [ 'api_platform.filter' ]
|
||||
|
||||
image.repository_filter:
|
||||
parent: 'App\Filter\ImageSearchRepositoryFilter'
|
||||
tags: [ 'api_platform.filter' ]
|
||||
|
||||
api_platform.filter.og_live.order:
|
||||
parent: 'api_platform.doctrine.orm.order_filter'
|
||||
arguments:
|
||||
|
|
|
@ -27,13 +27,13 @@ class TransferAction extends AbstractOgRepositoryController
|
|||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function __invoke(ExportImportImageRepositoryInput $input, ImageRepository $repository): JsonResponse
|
||||
public function __invoke(ExportImportImageRepositoryInput $input, Image $image): JsonResponse
|
||||
{
|
||||
$images = $input->images;
|
||||
$repositories = $input->repositories;
|
||||
|
||||
foreach ($images as $imageEntity) {
|
||||
/** @var Image $image */
|
||||
$image = $imageEntity->getEntity();
|
||||
foreach ($repositories as $repositoryEntity) {
|
||||
/** @var ImageRepository $repository */
|
||||
$repository = $repositoryEntity->getEntity();
|
||||
|
||||
if (!$image->getImageFullsum()) {
|
||||
throw new ValidatorException('Fullsum is required');
|
||||
|
|
|
@ -13,6 +13,6 @@ class ExportImportImageRepositoryInput
|
|||
* @var ImageOutput[]
|
||||
*/
|
||||
#[Assert\NotNull]
|
||||
#[Groups(['repository:write'])]
|
||||
public array $images = [];
|
||||
#[Groups(['image:write'])]
|
||||
public array $repositories = [];
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filter;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use Symfony\Component\PropertyInfo\Type;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
class ImageSearchRepositoryFilter extends AbstractFilter
|
||||
{
|
||||
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
|
||||
{
|
||||
if ($property !== 'repositoryId') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null === $value || '' === $value || 'undefined' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$alias = $queryBuilder->getRootAliases()[0];
|
||||
$joinAlias = $queryNameGenerator->generateJoinAlias('repositoryId');
|
||||
|
||||
$queryBuilder
|
||||
->innerJoin(sprintf('%s.repositories', $alias), $joinAlias)
|
||||
->andWhere(sprintf('%s.id = :repositoryId', $joinAlias))
|
||||
->setParameter('repositoryId', $value);
|
||||
}
|
||||
|
||||
public function getDescription(string $resourceClass): array
|
||||
{
|
||||
return [
|
||||
'repositoryId' => [
|
||||
'property' => 'repositoryId',
|
||||
'type' => Type::BUILTIN_TYPE_INT,
|
||||
'required' => false,
|
||||
'description' => 'Filter images by repository ID.',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
namespace App\Filter;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
||||
use Symfony\Component\PropertyInfo\Type;
|
||||
|
||||
class NotEqualIdFilter extends AbstractFilter
|
||||
|
@ -16,10 +17,24 @@ class NotEqualIdFilter extends AbstractFilter
|
|||
return;
|
||||
}
|
||||
|
||||
if (is_array($value) && isset($value['neq'])) {
|
||||
$value = $value['neq'];
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$value = array_map('intval', explode(',', $value));
|
||||
}
|
||||
|
||||
if (!is_array($value) || empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$alias = $queryBuilder->getRootAliases()[0];
|
||||
$paramName = $queryNameGenerator->generateParameterName('id');
|
||||
|
||||
$queryBuilder
|
||||
->andWhere(sprintf('%s.%s != :id', $alias, $property))
|
||||
->setParameter('id', $value);
|
||||
->andWhere(sprintf('%s.%s NOT IN (:%s)', $alias, $property, $paramName))
|
||||
->setParameter($paramName, $value);
|
||||
}
|
||||
|
||||
public function getDescription(string $resourceClass): array
|
||||
|
@ -29,7 +44,7 @@ class NotEqualIdFilter extends AbstractFilter
|
|||
'property' => 'id',
|
||||
'type' => Type::BUILTIN_TYPE_INT,
|
||||
'required' => false,
|
||||
'description' => 'Filter records where id is not equal to the given value.',
|
||||
'description' => 'Exclude records where id is in the given list.',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue