add get element use case

This commit is contained in:
Yisroel Baum 2026-05-26 19:59:09 +03:00
parent ca4d2dad3b
commit 46f5e6138e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 52 additions and 0 deletions

View 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;
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace App\Element\UseCases\GetElement;
class GetElementRequest
{
public function __construct(public ?int $id)
{
}
}

View file

@ -0,0 +1,9 @@
<?php
namespace App\Exceptions;
use DomainException;
class NotFoundException extends DomainException
{
}