id === null) { throw new BadRequestException('id is required'); } if ( $request->pdfContents === null || $request->pdfOriginalName === null || $request->pdfMimeType === null || $request->pdfSizeBytes === null ) { throw new BadRequestException('pdf is required'); } if ( ! in_array( $request->pdfMimeType, self::ALLOWED_MIME_TYPES, true, ) ) { throw new BadRequestException('pdf must be a pdf file'); } if ($request->pdfSizeBytes > self::MAX_SIZE_BYTES) { throw new BadRequestException('pdf must be 10MB or smaller'); } $element = $this->elementRepository->find($request->id); if ($element === null) { throw new NotFoundException('Element not found'); } $pdf = new FileToUpload( contents: $request->pdfContents, originalName: $request->pdfOriginalName, mimeType: $request->pdfMimeType, sizeBytes: $request->pdfSizeBytes, ); $path = $this->fileUploader->upload($pdf, 'element-pdfs'); $element->setPdfPath($path); return $this->elementRepository->update($element); } }