30 lines
676 B
PHP
30 lines
676 B
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Element\ElementRepository;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class ElementController
|
|
{
|
|
public function __construct(private ElementRepository $elementRepository)
|
|
{
|
|
}
|
|
|
|
public function show(int $id): JsonResponse
|
|
{
|
|
$element = $this->elementRepository->find($id);
|
|
if ($element === null) {
|
|
return new JsonResponse([
|
|
'error' => 'Element not found',
|
|
], 404);
|
|
}
|
|
|
|
return new JsonResponse([
|
|
'element' => [
|
|
'id' => $element->getId(),
|
|
'title' => $element->getTitle(),
|
|
],
|
|
], 200);
|
|
}
|
|
}
|