refactor element updates
This commit is contained in:
parent
581852ecbc
commit
d334745ade
19 changed files with 453 additions and 75 deletions
48
backend/app/Element/UseCases/UpdateElement/UpdatePdfPath.php
Normal file
48
backend/app/Element/UseCases/UpdateElement/UpdatePdfPath.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue