rename upload use cases

This commit is contained in:
Yisroel Baum 2026-06-02 16:38:59 +03:00
parent bd38e350cf
commit d0810ba4b3
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 12 additions and 12 deletions

View file

@ -1,81 +0,0 @@
<?php
namespace App\Element\UseCases\UpdateElement;
use App\Element\Element;
use App\Element\ElementRepository;
use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
use App\Shared\Files\FileToUpload;
use App\Shared\Files\FileUploader;
class UpdateElementIconImage
{
private const ALLOWED_MIME_TYPES = [
'image/jpeg',
'image/png',
'image/webp',
];
private const MAX_SIZE_BYTES = 5 * 1024 * 1024;
public function __construct(
private ElementRepository $elementRepository,
private FileUploader $fileUploader,
) {
}
/**
* @throws BadRequestException
* @throws NotFoundException
*/
public function execute(UpdateElementIconImageRequest $request): Element
{
if ($request->id === null) {
throw new BadRequestException('id is required');
}
if (
$request->iconImageContents === null
|| $request->iconImageOriginalName === null
|| $request->iconImageMimeType === null
|| $request->iconImageSizeBytes === null
) {
throw new BadRequestException('icon image is required');
}
if (
! in_array(
$request->iconImageMimeType,
self::ALLOWED_MIME_TYPES,
true,
)
) {
throw new BadRequestException(
'icon image must be a jpeg, png or webp image',
);
}
if ($request->iconImageSizeBytes > self::MAX_SIZE_BYTES) {
throw new BadRequestException(
'icon image must be 5MB or smaller',
);
}
$element = $this->elementRepository->find($request->id);
if ($element === null) {
throw new NotFoundException('Element not found');
}
$iconImage = new FileToUpload(
contents: $request->iconImageContents,
originalName: $request->iconImageOriginalName,
mimeType: $request->iconImageMimeType,
sizeBytes: $request->iconImageSizeBytes,
);
$path = $this->fileUploader->upload($iconImage, 'element-icons');
$element->setIconImageUrl($path);
return $this->elementRepository->update($element);
}
}