wire element use case
This commit is contained in:
parent
aa77ccad81
commit
28ea873f38
1 changed files with 16 additions and 6 deletions
|
|
@ -2,21 +2,31 @@
|
||||||
|
|
||||||
namespace App\Controllers;
|
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;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
class ElementController
|
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);
|
try {
|
||||||
if ($element === null) {
|
$element = $this->getElement->execute(
|
||||||
|
new GetElementRequest(id: $id)
|
||||||
|
);
|
||||||
|
} catch (BadRequestException $exception) {
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'error' => 'Element not found',
|
'error' => $exception->getMessage(),
|
||||||
|
], 400);
|
||||||
|
} catch (NotFoundException $exception) {
|
||||||
|
return new JsonResponse([
|
||||||
|
'error' => $exception->getMessage(),
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue