Refactor Images/Repositories modules
testing/ogcore-api/pipeline/head This commit looks good Details

pull/26/head
Manuel Aranda Rosales 2025-03-18 17:11:13 +01:00
parent ec7006db9a
commit 1f4a88df0f
5 changed files with 12 additions and 28 deletions

View File

@ -66,10 +66,6 @@ class ResponseController extends AbstractOgRepositoryController
$trace = $this->getTrace($data['job_id']);
if (!$trace) return $this->jsonResponseError('Trace not found');
if ($data['success'] !== true) {
return $this->jsonResponseError('Action failed', Response::HTTP_BAD_REQUEST, $trace);
}
$image = $this->getImage($trace);
$repository = $this->getRepository($trace);
$originImageImageRepository = $this->getImageImageRepository($trace);
@ -79,6 +75,11 @@ class ResponseController extends AbstractOgRepositoryController
$originImageImageRepository->setStatus(ImageStatus::SUCCESS);
$this->entityManager->persist($originImageImageRepository);
$this->entityManager->flush();
if ($data['success'] !== true) {
return $this->jsonResponseError('Action failed', Response::HTTP_BAD_REQUEST, $trace);
}
$newImageRepo = new ImageImageRepository();
$newImageRepo->setImage($image);

View File

@ -16,10 +16,13 @@ use Symfony\Component\Validator\Constraints as Assert;
final class ImageRepositoryInput
{
#[Assert\NotBlank]
#[Groups(['repository:write'])]
#[ApiProperty(description: 'The name of the repository', example: "Repository 1")]
public ?string $name = null;
#[Assert\NotBlank]
#[Assert\Ip]
#[Groups(['repository:write'])]
#[ApiProperty(description: 'The IP of the repository', example: "")]
public ?string $ip = null;

View File

@ -18,9 +18,6 @@ class ImageRepositoryOutput extends AbstractOutput
#[Groups(['repository:read'])]
public ?string $comments = '';
#[Groups(['repository:read'])]
public ?bool $status = true;
#[Groups(['repository:read'])]
public \DateTime $createdAt;
@ -34,7 +31,6 @@ class ImageRepositoryOutput extends AbstractOutput
$this->name = $imageRepository->getName();
$this->ip = $imageRepository->getIp();
$this->comments = $imageRepository->getComments();
$this->status = $status;
$this->createdAt = $imageRepository->getCreatedAt();
$this->createdBy = $imageRepository->getCreatedBy();
}

View File

@ -54,7 +54,7 @@ final readonly class ImageRepositorySubscriber implements EventSubscriberInterfa
$imagesToImport = $this->entityManager->getRepository(Image::class)->findBy(['isGlobal' => true]);
foreach($imagesToImport as $imageToImport) {
$this->transferIsGlobalAction->__invoke([$imageToImport], $imageRepositoryOutput->getEntity());
//$this->transferIsGlobalAction->__invoke($imageRepositoryOutput->getEntity());
}
}
}

View File

@ -9,23 +9,17 @@ use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\State\Pagination\TraversablePaginator;
use ApiPlatform\State\ProviderInterface;
use App\Controller\OgRepository\StatusAction;
use App\Dto\Input\ImageInput;
use App\Dto\Input\ImageRepositoryInput;
use App\Dto\Output\ImageOutput;
use App\Dto\Output\ImageRepositoryOutput;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
readonly class ImageRepositoryProvider implements ProviderInterface
{
public function __construct(
private ProviderInterface $collectionProvider,
private ProviderInterface $itemProvider,
private StatusAction $statusAction
private ProviderInterface $collectionProvider,
private ProviderInterface $itemProvider
)
{
}
@ -43,23 +37,13 @@ readonly class ImageRepositoryProvider implements ProviderInterface
}
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ClientExceptionInterface
*/
private function provideCollection(Operation $operation, array $uriVariables = [], array $context = []): object
{
$paginator = $this->collectionProvider->provide($operation, $uriVariables, $context);
$items = new \ArrayObject();
foreach ($paginator->getIterator() as $item){
$statusResponse = $this->statusAction->__invoke($item);
$content = json_decode($statusResponse->getContent(), true);
$status = !isset($content['error']);
$items[] = new ImageRepositoryOutput($item, $status);
$items[] = new ImageRepositoryOutput($item);
}
return new TraversablePaginator($items, $paginator->getCurrentPage(), $paginator->getItemsPerPage(), $paginator->getTotalItems());