add element updates

This commit is contained in:
Yisroel Baum 2026-05-28 20:08:36 +03:00
parent 6d0acaae56
commit 73b0befc97
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
10 changed files with 223 additions and 13 deletions

View file

@ -38,6 +38,36 @@ class EloquentElementRepository implements ElementRepository
);
}
public function update(Element $element, UpdateElementDto $dto): Element
{
$model = ElementModel::find($element->getId());
if ($model === null) {
throw new DomainException(
"Element with id: {$element->getId()} doesnt exist"
);
}
$model->title = $dto->title;
$model->description = $dto->description;
$model->icon_image_url = $dto->iconImageUrl;
$model->rich_text = $dto->richText;
$model->pdf_path = $dto->pdfPath;
$model->youtube_url = $dto->youtubeUrl;
$model->save();
return new Element(
id: $element->getId(),
title: $dto->title,
description: $dto->description,
iconImageUrl: $dto->iconImageUrl,
richText: $dto->richText,
pdfPath: $dto->pdfPath,
youtubeUrl: $dto->youtubeUrl,
set: $element->getSet(),
parentElement: $element->getParentElement(),
);
}
public function find(int $id): ?Element
{
$model = ElementModel::find($id);