add get element use case
This commit is contained in:
parent
ca4d2dad3b
commit
46f5e6138e
3 changed files with 52 additions and 0 deletions
33
backend/app/Element/UseCases/GetElement/GetElement.php
Normal file
33
backend/app/Element/UseCases/GetElement/GetElement.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Element\UseCases\GetElement;
|
||||||
|
|
||||||
|
use App\Element\Element;
|
||||||
|
use App\Element\ElementRepository;
|
||||||
|
use App\Exceptions\BadRequestException;
|
||||||
|
use App\Exceptions\NotFoundException;
|
||||||
|
|
||||||
|
class GetElement
|
||||||
|
{
|
||||||
|
public function __construct(private ElementRepository $elementRepository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws BadRequestException
|
||||||
|
* @throws NotFoundException
|
||||||
|
*/
|
||||||
|
public function execute(GetElementRequest $request): Element
|
||||||
|
{
|
||||||
|
if ($request->id === null) {
|
||||||
|
throw new BadRequestException('id is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
$element = $this->elementRepository->find($request->id);
|
||||||
|
if ($element === null) {
|
||||||
|
throw new NotFoundException('Element not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Element\UseCases\GetElement;
|
||||||
|
|
||||||
|
class GetElementRequest
|
||||||
|
{
|
||||||
|
public function __construct(public ?int $id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
9
backend/app/Exceptions/NotFoundException.php
Normal file
9
backend/app/Exceptions/NotFoundException.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use DomainException;
|
||||||
|
|
||||||
|
class NotFoundException extends DomainException
|
||||||
|
{
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue