refs #2944. New datasize column in Imange entity
testing/ogcore-api/pipeline/head There was a failure building this commit Details

pull/88/head
Manuel Aranda Rosales 2026-04-15 12:13:37 +02:00
parent 6a9d8bf8b2
commit 07101267a7
4 changed files with 69 additions and 2 deletions

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260415120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add size (compressed size) field to image_image_repository table';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE image_image_repository ADD size VARCHAR(255) DEFAULT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE image_image_repository DROP COLUMN size');
}
}

View File

@ -36,6 +36,24 @@ class GetAction extends AbstractOgRepositoryController
throw new BadRequestHttpException('An error occurred while fetching the image: ' . $content['details']);
}
$datasize = $content['details']['images'][0]['datasize'] ?? null;
$size = $content['details']['images'][0]['size'] ?? null;
$changed = false;
if ($datasize !== null && $data->getDatasize() !== (string) $datasize) {
$data->setDatasize((string) $datasize);
$changed = true;
}
if ($size !== null && $data->getSize() !== (string) $size) {
$data->setSize((string) $size);
$changed = true;
}
if ($changed) {
$this->entityManager->flush();
}
return new JsonResponse(data: $content, status: Response::HTTP_OK);
}
}

View File

@ -54,11 +54,18 @@ class ImageImageRepositoryOutput extends AbstractOutput
#[Groups(['image-image-repository:read', 'image:read'])]
#[ApiProperty(
description: 'El tamaño de los datos en bytes',
example: '10737418240'
description: 'El tamaño de los datos sin comprimir en bytes',
example: '12902400000'
)]
public ?string $datasize = null;
#[Groups(['image-image-repository:read', 'image:read'])]
#[ApiProperty(
description: 'El tamaño de la imagen comprimida en bytes',
example: '3795024506'
)]
public ?string $size = null;
#[Groups(['image-image-repository:read', 'image:read'])]
#[ApiProperty(
description: 'La descripción de la imagen',
@ -107,6 +114,7 @@ class ImageImageRepositoryOutput extends AbstractOutput
$this->status = $imageImageRepository->getStatus();
$this->imageFullsum = $imageImageRepository->getImageFullsum();
$this->datasize = $imageImageRepository->getDatasize();
$this->size = $imageImageRepository->getSize();
$this->description = $imageImageRepository->getDescription();
$this->createdAt = $imageImageRepository->getCreatedAt();
$this->createdBy = $imageImageRepository->getCreatedBy();

View File

@ -32,6 +32,9 @@ class ImageImageRepository extends AbstractEntity
#[ORM\Column(length: 255, nullable: true)]
private ?string $datasize = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $size = null;
#[ORM\Column(nullable: true)]
private ?int $version = null;
@ -125,6 +128,18 @@ class ImageImageRepository extends AbstractEntity
return $this;
}
public function getSize(): ?string
{
return $this->size;
}
public function setSize(?string $size): static
{
$this->size = $size;
return $this;
}
public function getVersion(): ?int
{
return $this->version;