* updated expressive version
This commit is contained in:
40
src/App/Handler/Pdf/GenerateMaintenanceSheetHandler.php
Normal file
40
src/App/Handler/Pdf/GenerateMaintenanceSheetHandler.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateMaintenanceSheetHandler extends CrudHandler
|
||||
{
|
||||
/** @var PdfService */
|
||||
private $pdfService;
|
||||
|
||||
/** @var MaintenanceManagerService */
|
||||
private $maintenanceManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->pdfService = $pdfService;
|
||||
$this->maintenanceManager = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
try {
|
||||
return (new TextResponse($this->pdfService->getMaintenanceSheet($id)))
|
||||
->withHeader('Content-type', 'application/pdf');
|
||||
} catch (\Exception $e) {
|
||||
return new TextResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user