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