refactor element updates

This commit is contained in:
Yisroel Baum 2026-05-28 20:33:14 +03:00
parent 581852ecbc
commit d334745ade
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
19 changed files with 453 additions and 75 deletions

View file

@ -0,0 +1,39 @@
<?php
namespace App\Element\UseCases\UpdateElement;
use App\Element\Element;
use App\Element\ElementRepository;
use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
class UpdateTitle
{
public function __construct(private ElementRepository $elementRepository)
{
}
/**
* @throws BadRequestException
* @throws NotFoundException
*/
public function execute(UpdateTitleRequest $request): Element
{
if ($request->id === null) {
throw new BadRequestException('id is required');
}
if ($request->title === null || trim($request->title) === '') {
throw new BadRequestException('title is required');
}
$element = $this->elementRepository->find($request->id);
if ($element === null) {
throw new NotFoundException('Element not found');
}
$element->setTitle(trim($request->title));
return $this->elementRepository->update($element);
}
}