diff --git a/config/api_platform/ImageRepository.yaml b/config/api_platform/ImageRepository.yaml index d7b6e79..84fda3b 100644 --- a/config/api_platform/ImageRepository.yaml +++ b/config/api_platform/ImageRepository.yaml @@ -13,6 +13,8 @@ resources: filters: - 'api_platform.filter.repository.order' - 'api_platform.filter.repository.search' + - 'repository.not_equal_filter' + ApiPlatform\Metadata\Get: provider: App\State\Provider\ImageRepositoryProvider ApiPlatform\Metadata\Put: @@ -64,14 +66,14 @@ resources: uriTemplate: /image-repositories/{uuid}/export-image controller: App\Controller\OgRepository\Image\ExportAction - import_image_ogrepository: + 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}/import-image - controller: App\Controller\OgRepository\Image\ImportAction + uriTemplate: /image-repositories/{uuid}/transfer-image + controller: App\Controller\OgRepository\Image\TransferAction properties: App\Entity\ImageRepository: diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index c9dd2af..0d61a42 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -55,7 +55,7 @@ services: api_platform.filter.image.order: parent: 'api_platform.doctrine.orm.order_filter' arguments: - $properties: { 'id': ~, 'name': ~, 'createdAt': ~ } + $properties: { 'id': ~, 'name': ~ } $orderParameterName: 'order' tags: [ 'api_platform.filter' ] @@ -190,6 +190,10 @@ services: arguments: [ { 'id': 'exact', 'name': 'partial'} ] tags: [ 'api_platform.filter' ] + repository.not_equal_filter: + parent: 'App\Filter\NotEqualIdFilter' + tags: [ 'api_platform.filter' ] + api_platform.filter.software.order: parent: 'api_platform.doctrine.orm.order_filter' arguments: diff --git a/src/Controller/OgRepository/Image/ImportAction.php b/src/Controller/OgRepository/Image/TransferAction.php similarity index 89% rename from src/Controller/OgRepository/Image/ImportAction.php rename to src/Controller/OgRepository/Image/TransferAction.php index d153f74..4c30498 100644 --- a/src/Controller/OgRepository/Image/ImportAction.php +++ b/src/Controller/OgRepository/Image/TransferAction.php @@ -19,7 +19,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; #[AsController] -class ImportAction extends AbstractOgRepositoryController +class TransferAction extends AbstractOgRepositoryController { /** * @throws TransportExceptionInterface @@ -53,13 +53,17 @@ class ImportAction extends AbstractOgRepositoryController $content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/repo/images', $params); + if (!isset($content['job_id'])) { + throw new ValidatorException('Job ID not found'); + } + $inputData = [ 'imageName' => $image->getName(), 'imageUuid' => $image->getUuid(), 'repositoryUuid' => $repository->getUuid(), ]; - $this->createService->__invoke($image->getClient(), CommandTypes::IMPORT_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); + $this->createService->__invoke($image->getClient(), CommandTypes::TRANSFER_IMAGE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); $image->setStatus(ImageStatus::TRANSFERRING); $this->entityManager->persist($image); diff --git a/src/Controller/OgRepository/Webhook/ResponseController.php b/src/Controller/OgRepository/Webhook/ResponseController.php index 57b76dc..3539d4d 100644 --- a/src/Controller/OgRepository/Webhook/ResponseController.php +++ b/src/Controller/OgRepository/Webhook/ResponseController.php @@ -44,10 +44,10 @@ class ResponseController extends AbstractOgRepositoryController if (str_starts_with($action, "CreateAuxiliarFiles_")) { $this->handleCreateAuxFiles($data); + } elseif (str_starts_with($action, "TransferImage_")) { + $this->processImageAction($data, 'transfer'); } elseif (str_starts_with($action, "ExportImage_")) { $this->processImageAction($data, 'export'); - } elseif (str_starts_with($action, "ImportImage_")) { - $this->processImageAction($data, 'import'); } else { return new JsonResponse(['message' => 'Invalid action'], Response::HTTP_BAD_REQUEST); } @@ -95,25 +95,9 @@ class ResponseController extends AbstractOgRepositoryController return; } - $this->logger->info("Image $actionType", ['image' => $image->getName()]); + $this->logger->info("Image $actionType successful", ['image' => $image->getName()]); - $params = [ - 'json' => [ - 'image' => $image->getName().'.img' - ] - ]; - - $this->logger->info('Creating aux files', ['image' => $image->getName()]); - $content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params); - - $inputData = [ - 'imageName' => $image->getName(), - 'imageUuid' => $image->getUuid(), - ]; - - $this->createService->__invoke($image->getClient(), CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); - - $image->setRepository($repository); + $image->addRepository($repository); $image->setStatus(ImageStatus::SUCCESS); $this->entityManager->persist($image); diff --git a/src/Filter/NotEqualIdFilter.php b/src/Filter/NotEqualIdFilter.php new file mode 100644 index 0000000..cf7d856 --- /dev/null +++ b/src/Filter/NotEqualIdFilter.php @@ -0,0 +1,36 @@ +getRootAliases()[0]; + $queryBuilder + ->andWhere(sprintf('%s.%s != :id', $alias, $property)) + ->setParameter('id', $value); + } + + public function getDescription(string $resourceClass): array + { + return [ + 'id[neq]' => [ + 'property' => 'id', + 'type' => Type::BUILTIN_TYPE_INT, + 'required' => false, + 'description' => 'Filter records where id is not equal to the given value.', + ], + ]; + } +} \ No newline at end of file diff --git a/src/Model/CommandTypes.php b/src/Model/CommandTypes.php index aac478f..79086c4 100644 --- a/src/Model/CommandTypes.php +++ b/src/Model/CommandTypes.php @@ -10,6 +10,7 @@ final class CommandTypes public const string CREATE_IMAGE_AUX_FILE = 'create-image-aux-file'; public const string IMPORT_IMAGE = 'import-image'; public const string EXPORT_IMAGE = 'export-image'; + public const string TRANSFER_IMAGE = 'transfer-image'; public const string POWER_ON = 'power-on'; public const string REBOOT = 'reboot'; public const string SHUTDOWN = 'shutdown';