48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Element\UseCases\UpdateElement;
|
|
|
|
use App\Element\Element;
|
|
use App\Element\ElementRepository;
|
|
use App\Exceptions\BadRequestException;
|
|
use App\Exceptions\NotFoundException;
|
|
|
|
class UpdatePdfPath
|
|
{
|
|
public function __construct(private ElementRepository $elementRepository)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @throws BadRequestException
|
|
* @throws NotFoundException
|
|
*/
|
|
public function execute(UpdatePdfPathRequest $request): Element
|
|
{
|
|
if ($request->id === null) {
|
|
throw new BadRequestException('id is required');
|
|
}
|
|
|
|
if ($request->pdfPath === null) {
|
|
throw new BadRequestException('pdfPath is required');
|
|
}
|
|
|
|
$element = $this->elementRepository->find($request->id);
|
|
if ($element === null) {
|
|
throw new NotFoundException('Element not found');
|
|
}
|
|
|
|
$element->setPdfPath($this->nullableString($request->pdfPath));
|
|
|
|
return $this->elementRepository->update($element);
|
|
}
|
|
|
|
private function nullableString(string $value): ?string
|
|
{
|
|
if ($value === '') {
|
|
return null;
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|