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.order'
|
||||||
- 'api_platform.filter.image.search'
|
- 'api_platform.filter.image.search'
|
||||||
- 'api_platform.filter.image.boolean'
|
- 'api_platform.filter.image.boolean'
|
||||||
|
- 'image.repository_filter'
|
||||||
|
|
||||||
ApiPlatform\Metadata\Get:
|
ApiPlatform\Metadata\Get:
|
||||||
provider: App\State\Provider\ImageProvider
|
provider: App\State\Provider\ImageProvider
|
||||||
ApiPlatform\Metadata\Put:
|
ApiPlatform\Metadata\Put:
|
||||||
|
@ -77,6 +79,15 @@ resources:
|
||||||
uriTemplate: /images/server/{uuid}/recover
|
uriTemplate: /images/server/{uuid}/recover
|
||||||
controller: App\Controller\OgRepository\Image\RecoverAction
|
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:
|
properties:
|
||||||
App\Entity\Image:
|
App\Entity\Image:
|
||||||
id:
|
id:
|
||||||
|
|
|
@ -66,15 +66,6 @@ resources:
|
||||||
uriTemplate: /image-repositories/{uuid}/export-image
|
uriTemplate: /image-repositories/{uuid}/export-image
|
||||||
controller: App\Controller\OgRepository\Image\ExportAction
|
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:
|
properties:
|
||||||
App\Entity\ImageRepository:
|
App\Entity\ImageRepository:
|
||||||
id:
|
id:
|
||||||
|
|
|
@ -69,6 +69,10 @@ services:
|
||||||
arguments: [ { 'created': ~ } ]
|
arguments: [ { 'created': ~ } ]
|
||||||
tags: [ 'api_platform.filter' ]
|
tags: [ 'api_platform.filter' ]
|
||||||
|
|
||||||
|
image.repository_filter:
|
||||||
|
parent: 'App\Filter\ImageSearchRepositoryFilter'
|
||||||
|
tags: [ 'api_platform.filter' ]
|
||||||
|
|
||||||
api_platform.filter.og_live.order:
|
api_platform.filter.og_live.order:
|
||||||
parent: 'api_platform.doctrine.orm.order_filter'
|
parent: 'api_platform.doctrine.orm.order_filter'
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
@ -27,13 +27,13 @@ class TransferAction extends AbstractOgRepositoryController
|
||||||
* @throws RedirectionExceptionInterface
|
* @throws RedirectionExceptionInterface
|
||||||
* @throws ClientExceptionInterface
|
* @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) {
|
foreach ($repositories as $repositoryEntity) {
|
||||||
/** @var Image $image */
|
/** @var ImageRepository $repository */
|
||||||
$image = $imageEntity->getEntity();
|
$repository = $repositoryEntity->getEntity();
|
||||||
|
|
||||||
if (!$image->getImageFullsum()) {
|
if (!$image->getImageFullsum()) {
|
||||||
throw new ValidatorException('Fullsum is required');
|
throw new ValidatorException('Fullsum is required');
|
||||||
|
|
|
@ -13,6 +13,6 @@ class ExportImportImageRepositoryInput
|
||||||
* @var ImageOutput[]
|
* @var ImageOutput[]
|
||||||
*/
|
*/
|
||||||
#[Assert\NotNull]
|
#[Assert\NotNull]
|
||||||
#[Groups(['repository:write'])]
|
#[Groups(['image:write'])]
|
||||||
public array $images = [];
|
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;
|
namespace App\Filter;
|
||||||
|
|
||||||
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
|
||||||
use ApiPlatform\Metadata\Operation;
|
|
||||||
use Doctrine\ORM\QueryBuilder;
|
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;
|
use Symfony\Component\PropertyInfo\Type;
|
||||||
|
|
||||||
class NotEqualIdFilter extends AbstractFilter
|
class NotEqualIdFilter extends AbstractFilter
|
||||||
|
@ -16,10 +17,24 @@ class NotEqualIdFilter extends AbstractFilter
|
||||||
return;
|
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];
|
$alias = $queryBuilder->getRootAliases()[0];
|
||||||
|
$paramName = $queryNameGenerator->generateParameterName('id');
|
||||||
|
|
||||||
$queryBuilder
|
$queryBuilder
|
||||||
->andWhere(sprintf('%s.%s != :id', $alias, $property))
|
->andWhere(sprintf('%s.%s NOT IN (:%s)', $alias, $property, $paramName))
|
||||||
->setParameter('id', $value);
|
->setParameter($paramName, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription(string $resourceClass): array
|
public function getDescription(string $resourceClass): array
|
||||||
|
@ -29,7 +44,7 @@ class NotEqualIdFilter extends AbstractFilter
|
||||||
'property' => 'id',
|
'property' => 'id',
|
||||||
'type' => Type::BUILTIN_TYPE_INT,
|
'type' => Type::BUILTIN_TYPE_INT,
|
||||||
'required' => false,
|
'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