Rabbi_Gerzi/backend/app/Element/UseCases/GetElement/GetElement.php

33 lines
768 B
PHP

<?php
namespace App\Element\UseCases\GetElement;
use App\Element\Element;
use App\Element\ElementRepository;
use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
class GetElement
{
public function __construct(private ElementRepository $elementRepository)
{
}
/**
* @throws BadRequestException
* @throws NotFoundException
*/
public function execute(GetElementRequest $request): Element
{
if ($request->id === null) {
throw new BadRequestException('id is required');
}
$element = $this->elementRepository->find($request->id);
if ($element === null) {
throw new NotFoundException('Element not found');
}
return $element;
}
}