find elements by set

This commit is contained in:
Yisroel Baum 2026-05-25 08:12:50 +03:00
parent aaa494afe4
commit b44830fa53
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 12 additions and 6 deletions

View file

@ -6,6 +6,7 @@ use App\Element\CreateElementDto;
use App\Element\Element;
use App\Element\ElementRepository;
use App\Exceptions\BadRequestException;
use App\Set\Set as DomainSet;
use App\Set\SetRepository;
use DomainException;
@ -37,7 +38,7 @@ class CreateElement
}
if ($request->parentElementId === null) {
$this->validateNoRootElementExists($request->setId);
$this->validateNoRootElementExists($set);
return $this->elementRepo->create(new CreateElementDto(
set: $set,
@ -70,9 +71,9 @@ class CreateElement
/**
* @throws DomainException
*/
private function validateNoRootElementExists(int $setId): void
private function validateNoRootElementExists(DomainSet $set): void
{
$elements = $this->elementRepo->findBySetId($setId);
$elements = $this->elementRepo->findBySet($set);
foreach ($elements as $element) {
if ($element->getParentElement() === null) {
throw new DomainException(