diff --git a/backend/app/Controllers/ElementController.php b/backend/app/Controllers/ElementController.php index 31fd90c..5fc14d7 100644 --- a/backend/app/Controllers/ElementController.php +++ b/backend/app/Controllers/ElementController.php @@ -69,8 +69,8 @@ class ElementController } public function showPdf( - string $folder, - string $fileName, + ?string $folder, + ?string $fileName, ): Response|JsonResponse { try { $result = $this->getElementPdf->execute( @@ -79,6 +79,10 @@ class ElementController fileName: $fileName, ) ); + } catch (BadRequestException $exception) { + return new JsonResponse([ + 'error' => $exception->getMessage(), + ], 400); } catch (NotFoundException $exception) { return new JsonResponse([ 'error' => $exception->getMessage(), diff --git a/backend/app/Element/UseCases/GetElementPdf/GetElementPdf.php b/backend/app/Element/UseCases/GetElementPdf/GetElementPdf.php index a742ac3..e210c61 100644 --- a/backend/app/Element/UseCases/GetElementPdf/GetElementPdf.php +++ b/backend/app/Element/UseCases/GetElementPdf/GetElementPdf.php @@ -2,6 +2,7 @@ namespace App\Element\UseCases\GetElementPdf; +use App\Exceptions\BadRequestException; use App\Exceptions\NotFoundException; use App\Shared\Files\Filesystem; @@ -16,10 +17,19 @@ class GetElementPdf } /** + * @throws BadRequestException * @throws NotFoundException */ 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)) { throw new NotFoundException('PDF not found'); } diff --git a/backend/app/Element/UseCases/GetElementPdf/GetElementPdfRequest.php b/backend/app/Element/UseCases/GetElementPdf/GetElementPdfRequest.php index 8824afd..ba7b565 100644 --- a/backend/app/Element/UseCases/GetElementPdf/GetElementPdfRequest.php +++ b/backend/app/Element/UseCases/GetElementPdf/GetElementPdfRequest.php @@ -5,8 +5,8 @@ namespace App\Element\UseCases\GetElementPdf; class GetElementPdfRequest { public function __construct( - public string $folder, - public string $fileName, + public ?string $folder, + public ?string $fileName, ) { } }