wire element use case

This commit is contained in:
Yisroel Baum 2026-05-26 20:00:42 +03:00
parent aa77ccad81
commit 28ea873f38
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -2,21 +2,31 @@
namespace App\Controllers;
use App\Element\ElementRepository;
use App\Element\UseCases\GetElement\GetElement;
use App\Element\UseCases\GetElement\GetElementRequest;
use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
use Illuminate\Http\JsonResponse;
class ElementController
{
public function __construct(private ElementRepository $elementRepository)
public function __construct(private GetElement $getElement)
{
}
public function show(int $id): JsonResponse
public function show(?int $id): JsonResponse
{
$element = $this->elementRepository->find($id);
if ($element === null) {
try {
$element = $this->getElement->execute(
new GetElementRequest(id: $id)
);
} catch (BadRequestException $exception) {
return new JsonResponse([
'error' => 'Element not found',
'error' => $exception->getMessage(),
], 400);
} catch (NotFoundException $exception) {
return new JsonResponse([
'error' => $exception->getMessage(),
], 404);
}