add element child list
This commit is contained in:
parent
aa746fe3f0
commit
7350d747f3
9 changed files with 186 additions and 10 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Element\UseCases\GetElement;
|
||||
|
||||
use App\Element\Element;
|
||||
use App\Element\ElementRepository;
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Exceptions\NotFoundException;
|
||||
|
|
@ -17,7 +16,7 @@ class GetElement
|
|||
* @throws BadRequestException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function execute(GetElementRequest $request): Element
|
||||
public function execute(GetElementRequest $request): GetElementResult
|
||||
{
|
||||
if ($request->id === null) {
|
||||
throw new BadRequestException('id is required');
|
||||
|
|
@ -28,6 +27,10 @@ class GetElement
|
|||
throw new NotFoundException('Element not found');
|
||||
}
|
||||
|
||||
return $element;
|
||||
return new GetElementResult(
|
||||
element: $element,
|
||||
childElements: $this->elementRepository
|
||||
->findByParentElement($element),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
backend/app/Element/UseCases/GetElement/GetElementResult.php
Normal file
30
backend/app/Element/UseCases/GetElement/GetElementResult.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Element\UseCases\GetElement;
|
||||
|
||||
use App\Element\Element;
|
||||
|
||||
class GetElementResult
|
||||
{
|
||||
/**
|
||||
* @param Element[] $childElements
|
||||
*/
|
||||
public function __construct(
|
||||
private Element $element,
|
||||
private array $childElements,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getElement(): Element
|
||||
{
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Element[]
|
||||
*/
|
||||
public function getChildElements(): array
|
||||
{
|
||||
return $this->childElements;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue