From 28ea873f385c861e164343353df097be9b5a13c2 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Tue, 26 May 2026 20:00:42 +0300 Subject: [PATCH] wire element use case --- backend/app/Controllers/ElementController.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/backend/app/Controllers/ElementController.php b/backend/app/Controllers/ElementController.php index 9e61720..62a6385 100644 --- a/backend/app/Controllers/ElementController.php +++ b/backend/app/Controllers/ElementController.php @@ -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); }