Rabbi_Gerzi/backend/app/Element/UseCases/UpdateElement/UpdateRichText.php

39 lines
986 B
PHP

<?php
namespace App\Element\UseCases\UpdateElement;
use App\Element\Element;
use App\Element\ElementRepository;
use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
class UpdateRichText
{
public function __construct(private ElementRepository $elementRepository)
{
}
/**
* @throws BadRequestException
* @throws NotFoundException
*/
public function execute(UpdateRichTextRequest $request): Element
{
if ($request->id === null) {
throw new BadRequestException('id is required');
}
if ($request->richText === null) {
throw new BadRequestException('richText is required');
}
$element = $this->elementRepository->find($request->id);
if ($element === null) {
throw new NotFoundException('Element not found');
}
$element->setRichText($request->richText);
return $this->elementRepository->update($element);
}
}