add child creation

This commit is contained in:
Yisroel Baum 2026-06-21 22:02:36 +03:00
parent 7c84eefe78
commit 34b0fd0b44
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
7 changed files with 332 additions and 2 deletions

View file

@ -0,0 +1,50 @@
<?php
namespace App\Element\UseCases\CreateChildElement;
use App\Element\CreateElementDto;
use App\Element\Element;
use App\Element\ElementRepository;
use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
class CreateChildElement
{
public function __construct(private ElementRepository $elementRepository)
{
}
/**
* @throws BadRequestException
* @throws NotFoundException
*/
public function execute(CreateChildElementRequest $request): Element
{
if ($request->parentElementId === null) {
throw new BadRequestException('parentElementId is required');
}
if ($request->title === null || $request->title === '') {
throw new BadRequestException('title is required');
}
$parentElement = $this->elementRepository->find(
$request->parentElementId
);
if ($parentElement === null) {
throw new NotFoundException('Parent element not found');
}
return $this->elementRepository->create(new CreateElementDto(
set: $parentElement->getSet(),
title: $request->title,
description: '',
iconImageUrl: null,
richText: '',
shortPdfPath: null,
longPdfPath: null,
youtubeUrl: null,
parentElement: $parentElement,
));
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace App\Element\UseCases\CreateChildElement;
class CreateChildElementRequest
{
public function __construct(
public ?int $parentElementId,
public ?string $title,
) {
}
}