handle nullable pdf params
This commit is contained in:
parent
9126b0e968
commit
8c8ee4c050
3 changed files with 18 additions and 4 deletions
|
|
@ -69,8 +69,8 @@ class ElementController
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showPdf(
|
public function showPdf(
|
||||||
string $folder,
|
?string $folder,
|
||||||
string $fileName,
|
?string $fileName,
|
||||||
): Response|JsonResponse {
|
): Response|JsonResponse {
|
||||||
try {
|
try {
|
||||||
$result = $this->getElementPdf->execute(
|
$result = $this->getElementPdf->execute(
|
||||||
|
|
@ -79,6 +79,10 @@ class ElementController
|
||||||
fileName: $fileName,
|
fileName: $fileName,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} catch (BadRequestException $exception) {
|
||||||
|
return new JsonResponse([
|
||||||
|
'error' => $exception->getMessage(),
|
||||||
|
], 400);
|
||||||
} catch (NotFoundException $exception) {
|
} catch (NotFoundException $exception) {
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'error' => $exception->getMessage(),
|
'error' => $exception->getMessage(),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Element\UseCases\GetElementPdf;
|
namespace App\Element\UseCases\GetElementPdf;
|
||||||
|
|
||||||
|
use App\Exceptions\BadRequestException;
|
||||||
use App\Exceptions\NotFoundException;
|
use App\Exceptions\NotFoundException;
|
||||||
use App\Shared\Files\Filesystem;
|
use App\Shared\Files\Filesystem;
|
||||||
|
|
||||||
|
|
@ -16,10 +17,19 @@ class GetElementPdf
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @throws BadRequestException
|
||||||
* @throws NotFoundException
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function execute(GetElementPdfRequest $request): GetElementPdfResult
|
public function execute(GetElementPdfRequest $request): GetElementPdfResult
|
||||||
{
|
{
|
||||||
|
if ($request->folder === null) {
|
||||||
|
throw new BadRequestException('folder is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->fileName === null) {
|
||||||
|
throw new BadRequestException('fileName is required');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->isAllowedPdfFolder($request->folder)) {
|
if (!$this->isAllowedPdfFolder($request->folder)) {
|
||||||
throw new NotFoundException('PDF not found');
|
throw new NotFoundException('PDF not found');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ namespace App\Element\UseCases\GetElementPdf;
|
||||||
class GetElementPdfRequest
|
class GetElementPdfRequest
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $folder,
|
public ?string $folder,
|
||||||
public string $fileName,
|
public ?string $fileName,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue