* updated expressive version
This commit is contained in:
@@ -1,182 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Json\Json;
|
||||
|
||||
abstract class AbstractCrudAction implements ServerMiddlewareInterface
|
||||
{
|
||||
const IDENTIFIER_NAME = 'id';
|
||||
const CORS_ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$requestMethod = strtoupper($request->getMethod());
|
||||
$id = $request->getAttribute(static::IDENTIFIER_NAME);
|
||||
|
||||
switch ($requestMethod) {
|
||||
case 'GET':
|
||||
return isset($id)
|
||||
? $this->get($request, $delegate)
|
||||
: $this->getList($request, $delegate);
|
||||
case 'POST':
|
||||
return $this->create($request, $delegate);
|
||||
case 'PUT':
|
||||
return $this->update($request, $delegate);
|
||||
case 'DELETE':
|
||||
return isset($id)
|
||||
? $this->delete($request, $delegate)
|
||||
: $this->deleteList($request, $delegate);
|
||||
case 'HEAD':
|
||||
return $this->head($request, $delegate);
|
||||
case 'OPTIONS':
|
||||
return $this->options($request, $delegate);
|
||||
case 'PATCH':
|
||||
return $this->patch($request, $delegate);
|
||||
default:
|
||||
return $delegate->process($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function delete(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function deleteList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function head(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function patch(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
final protected function createResponse($data, $status = 200)
|
||||
{
|
||||
return new JsonResponse($data, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return array|object
|
||||
*/
|
||||
public function getRequestData(ServerRequestInterface $request)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
|
||||
if (!empty($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
return $this->parseRequestData(
|
||||
$request->getBody()->getContents(),
|
||||
$request->getHeaderLine('content-type')
|
||||
);
|
||||
}
|
||||
|
||||
protected function withCorsHeaders(ResponseInterface $response, iterable $methods = [])
|
||||
{
|
||||
if ($methods) {
|
||||
$methodsHeader = implode(',', $methods);
|
||||
$response = $response->withHeader('Accept', $methodsHeader)
|
||||
->withHeader('Access-Control-Allow-Methods', $methodsHeader);
|
||||
}
|
||||
return $response
|
||||
->withHeader('Access-Control-Allow-Origin', '*')
|
||||
->withHeader('Access-Control-Allow-Headers', implode(",", self::CORS_ALLOW_HEADERS));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $contentType
|
||||
* @return mixed
|
||||
*/
|
||||
private function parseRequestData($input, $contentType)
|
||||
{
|
||||
$contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
|
||||
$parser = $this->returnParserContentType($contentTypeParts[0]);
|
||||
|
||||
return $parser($input);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $contentType
|
||||
* @return callable
|
||||
*/
|
||||
private function returnParserContentType(string $contentType)
|
||||
{
|
||||
if ($contentType === 'application/x-www-form-urlencoded') {
|
||||
return function ($input) {
|
||||
parse_str($input, $data);
|
||||
return $data;
|
||||
};
|
||||
} elseif ($contentType === 'application/json') {
|
||||
return function ($input) {
|
||||
$jsonDecoder = new Json();
|
||||
try {
|
||||
return $jsonDecoder->decode($input, Json::TYPE_ARRAY);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} elseif ($contentType === 'multipart/form-data') {
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Auth;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\AuthService;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class AuthAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var AuthService
|
||||
*/
|
||||
private $authService;
|
||||
|
||||
public function __construct(AuthService $authService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new auth token (login)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$authData = $this->getRequestData($request);
|
||||
try {
|
||||
return new JsonCorsResponse($this->authService->authenticate($authData['login'], $authData['password']));
|
||||
} catch (NoResultException $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 403);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
try {
|
||||
$token = $request->getAttribute('token', false);
|
||||
return new JsonCorsResponse($this->authService->renewToken($token));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class ErrorCategoryAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ErrorCategoryService
|
||||
*/
|
||||
private $errorCategoryService;
|
||||
|
||||
public function __construct(ErrorCategoryService $errorCategoryService)
|
||||
{
|
||||
$this->errorCategoryService = $errorCategoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->errorCategoryService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\ErrorOriginService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class ErrorOriginAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ErrorOriginService
|
||||
*/
|
||||
private $errorOriginService;
|
||||
|
||||
public function __construct(ErrorOriginService $errorOriginService)
|
||||
{
|
||||
$this->errorOriginService = $errorOriginService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->errorOriginService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FacilityLocationService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FacilityLocationAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FacilityLocationService
|
||||
*/
|
||||
private $facilityLocationService;
|
||||
|
||||
public function __construct(FacilityLocationService $facilityLocationService)
|
||||
{
|
||||
$this->facilityLocationService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->facilityLocationService->getFacilityLocationListFlat());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
'PUT',
|
||||
'PATCH',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->faultManagerService->getFaultList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single fault
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
return new JsonCorsResponse($this->faultManagerService->getFault($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
$token = $request->getAttribute('token');
|
||||
return new JsonCorsResponse($this->faultManagerService->createFault($data, $token->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$token = $request->getAttribute('token');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->updateFault($id, $data, $token->uid));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a fault report (NYI)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function delete(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
return new JsonCorsResponse($this->faultManagerService->deleteFault($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultCommentAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->addFaultComment($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultRejectAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->rejectFault($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS2ConfirmAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->confirmFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS3AcknowledgeAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->ackFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS4RepairedAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->repairFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS5AcceptedAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->acceptFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class MaintenanceAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->getMaintenanceList()->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse|\Zend\Diactoros\Response\JsonResponse
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->get($hash));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse|\Zend\Diactoros\Response\JsonResponse
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
$data = $this->getRequestData($request);
|
||||
$jwt = $request->getAttribute('token');
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->update($hash, $data, $jwt->uid));
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class MaintenanceUpcomingAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->getUpcomingMaintenanceList()->getValues());
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateMaintenanceSheetAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var PdfService
|
||||
*/
|
||||
private $pdfService;
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->pdfService = $pdfService;
|
||||
$this->maintenanceManager = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse|TextResponse|static
|
||||
* @throws \PHPPdf\Core\PHPPdf\Exception\Exception
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class PingAction implements ServerMiddlewareInterface
|
||||
{
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse(['ack' => time()]);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class SolutionTimeIntervalAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var SolutionTimeIntervalService
|
||||
*/
|
||||
private $solutionTimeIntervalService;
|
||||
|
||||
public function __construct(SolutionTimeIntervalService $facilityLocationService)
|
||||
{
|
||||
$this->solutionTimeIntervalService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->solutionTimeIntervalService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\UserService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class PasswordAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$token = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->userService->changePassword($token->uid, $data['old'], $data['new']));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\UserService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class UserAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
try {
|
||||
return new JsonCorsResponse($this->userService->getList());
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
return new JsonCorsResponse($this->userService->get($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->userService->update($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\DeviceGroup;
|
||||
use App\Entity\DeviceMaintenanceTask;
|
||||
use App\Entity\Maintenance;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
@@ -37,6 +36,7 @@ class ConvertMaintenanceHashCommand extends Command
|
||||
* @param OutputInterface $output
|
||||
* @return int|null|void
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\Mailer\MailerService;
|
||||
use App\Service\MailerService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class MailTestCommand extends Command
|
||||
class DebugMailCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var MailerService
|
||||
*/
|
||||
/** @var MailerService */
|
||||
private $mailerService;
|
||||
|
||||
public function __construct(MailerService $mailerService)
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\Mailer\MailerService;
|
||||
use App\Service\MailerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class MailTestCommandFactory
|
||||
class DebugMailCommandFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var MailerService $mailerService */
|
||||
$mailerService = $container->get(MailerService::class);
|
||||
return new MailTestCommand($mailerService);
|
||||
return new DebugMailCommand($mailerService);
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,12 @@ namespace App\Command;
|
||||
|
||||
use App\Service\FixtureLoaderService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class InitializeFixtureCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var FixtureLoaderService
|
||||
*/
|
||||
/** @var FixtureLoaderService */
|
||||
private $fixtureLoaderService;
|
||||
|
||||
public function __construct(FixtureLoaderService $fixtureLoaderService)
|
||||
|
||||
@@ -36,26 +36,26 @@ class ConfigProvider
|
||||
{
|
||||
return [
|
||||
'invokables' => [
|
||||
Action\PingAction::class => Action\PingAction::class,
|
||||
Handler\PingHandler::class => Handler\PingHandler::class,
|
||||
|
||||
],
|
||||
'factories' => [
|
||||
Action\MaintenanceAction::class => Action\MaintenanceFactory::class,
|
||||
Action\MaintenanceUpcomingAction::class => Action\MaintenanceUpcomingFactory::class,
|
||||
Handler\MaintenanceHandler::class => Handler\MaintenanceFactory::class,
|
||||
Handler\MaintenanceUpcomingHandler::class => Handler\MaintenanceUpcomingFactory::class,
|
||||
|
||||
Action\Auth\AuthAction::class => Action\Auth\AuthFactory::class,
|
||||
Action\User\UserAction::class => Action\User\UserFactory::class,
|
||||
Action\User\PasswordAction::class => Action\User\PasswordFactory::class,
|
||||
Action\Fault\FaultAction::class => Action\Fault\FaultFactory::class,
|
||||
Action\Fault\FaultAttachmentAction::class => Action\Fault\FaultAttachmentFactory::class,
|
||||
Action\Fault\FaultCommentAction::class => Action\Fault\FaultCommentFactory::class,
|
||||
Action\Fault\FaultRejectAction::class => Action\Fault\FaultRejectFactory::class,
|
||||
Action\ErrorOriginAction::class => Action\ErrorOriginFactory::class,
|
||||
Action\ErrorCategoryAction::class => Action\ErrorCategoryFactory::class,
|
||||
Action\FacilityLocationAction::class => Action\FacilityLocationFactory::class,
|
||||
Action\SolutionTimeIntervalAction::class => Action\SolutionTimeIntervalFactory::class,
|
||||
Action\Pdf\GenerateWorksheetAction::class => Action\Pdf\GenerateWorksheetFactory::class,
|
||||
Action\Pdf\GenerateMaintenanceSheetAction::class => Action\Pdf\GenerateMaintenanceSheetFactory::class,
|
||||
Handler\Auth\AuthHandler::class => Handler\Auth\AuthFactory::class,
|
||||
Handler\User\UserHandler::class => Handler\User\UserFactory::class,
|
||||
Handler\User\PasswordHandler::class => Handler\User\PasswordFactory::class,
|
||||
Handler\Fault\FaultHandler::class => Handler\Fault\FaultFactory::class,
|
||||
Handler\Fault\FaultAttachmentHandler::class => Handler\Fault\FaultAttachmentFactory::class,
|
||||
Handler\Fault\FaultCommentHandler::class => Handler\Fault\FaultCommentFactory::class,
|
||||
Handler\Fault\FaultRejectHandler::class => Handler\Fault\FaultRejectFactory::class,
|
||||
Handler\ErrorOriginHandler::class => Handler\ErrorOriginFactory::class,
|
||||
Handler\ErrorCategoryHandler::class => Handler\ErrorCategoryFactory::class,
|
||||
Handler\FacilityLocationHandler::class => Handler\FacilityLocationFactory::class,
|
||||
Handler\SolutionTimeIntervalHandler::class => Handler\SolutionTimeIntervalFactory::class,
|
||||
Handler\Pdf\GenerateWorksheetHandler::class => Handler\Pdf\GenerateWorksheetFactory::class,
|
||||
Handler\Pdf\GenerateMaintenanceSheetHandler::class => Handler\Pdf\GenerateMaintenanceSheetFactory::class,
|
||||
|
||||
Service\AuthService::class => Service\AuthServiceFactory::class,
|
||||
Service\UserService::class => Service\UserServiceFactory::class,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Auth;
|
||||
namespace App\Handler\Auth;
|
||||
|
||||
use App\Service\AuthService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -10,6 +10,6 @@ class AuthFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(AuthService::class);
|
||||
return new AuthAction($faultManagerService);
|
||||
return new AuthHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
59
src/App/Handler/Auth/AuthHandler.php
Normal file
59
src/App/Handler/Auth/AuthHandler.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Auth;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\AuthService;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class AuthHandler extends CrudHandler
|
||||
{
|
||||
/** @var AuthService */
|
||||
private $authService;
|
||||
|
||||
public function __construct(AuthService $authService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new auth token (login)
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$authData = $this->getRequestData($request);
|
||||
try {
|
||||
return new JsonResponse($this->authService->authenticate($authData['login'], $authData['password']));
|
||||
} catch (NoResultException $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 403);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$token = $request->getAttribute('token', false);
|
||||
return new JsonResponse($this->authService->renewToken($token));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -11,6 +11,6 @@ class ErrorCategoryFactory
|
||||
{
|
||||
/** @var ErrorCategoryService $errorCategoryService */
|
||||
$errorCategoryService = $container->get(ErrorCategoryService::class);
|
||||
return new ErrorCategoryAction($errorCategoryService);
|
||||
return new ErrorCategoryHandler($errorCategoryService);
|
||||
}
|
||||
}
|
||||
30
src/App/Handler/ErrorCategoryHandler.php
Normal file
30
src/App/Handler/ErrorCategoryHandler.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class ErrorCategoryHandler extends CrudHandler
|
||||
{
|
||||
/** @var ErrorCategoryService */
|
||||
private $errorCategoryService;
|
||||
|
||||
public function __construct(ErrorCategoryService $errorCategoryService)
|
||||
{
|
||||
$this->errorCategoryService = $errorCategoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->errorCategoryService->getList());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\ErrorOriginService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -11,6 +11,6 @@ class ErrorOriginFactory
|
||||
{
|
||||
/** @var ErrorOriginService $errorOriginService */
|
||||
$errorOriginService = $container->get(ErrorOriginService::class);
|
||||
return new ErrorOriginAction($errorOriginService);
|
||||
return new ErrorOriginHandler($errorOriginService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/ErrorOriginHandler.php
Normal file
31
src/App/Handler/ErrorOriginHandler.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\ErrorOriginService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class ErrorOriginHandler extends CrudHandler
|
||||
{
|
||||
/** @var ErrorOriginService */
|
||||
private $errorOriginService;
|
||||
|
||||
public function __construct(ErrorOriginService $errorOriginService)
|
||||
{
|
||||
$this->errorOriginService = $errorOriginService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->errorOriginService->getList());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\FacilityLocationService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -11,6 +11,6 @@ class FacilityLocationFactory
|
||||
{
|
||||
/** @var FacilityLocationService $facilityLocationService */
|
||||
$facilityLocationService = $container->get(FacilityLocationService::class);
|
||||
return new FacilityLocationAction($facilityLocationService);
|
||||
return new FacilityLocationHandler($facilityLocationService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/FacilityLocationHandler.php
Normal file
31
src/App/Handler/FacilityLocationHandler.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FacilityLocationService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FacilityLocationHandler extends CrudHandler
|
||||
{
|
||||
/** @var FacilityLocationService */
|
||||
private $facilityLocationService;
|
||||
|
||||
public function __construct(FacilityLocationService $facilityLocationService)
|
||||
{
|
||||
$this->facilityLocationService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->facilityLocationService->getFacilityLocationListFlat());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultAttachmentService;
|
||||
use App\Service\FaultManagerService;
|
||||
@@ -12,6 +12,6 @@ class FaultAttachmentFactory
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
$attachmentService = $container->get(FaultAttachmentService::class);
|
||||
return new FaultAttachmentAction($faultManagerService, $attachmentService);
|
||||
return new FaultAttachmentHandler($faultManagerService, $attachmentService);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultAttachmentService;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
class FaultAttachmentAction extends AbstractCrudAction
|
||||
class FaultAttachmentHandler extends CrudHandler
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
/**
|
||||
* @var FaultAttachmentService
|
||||
*/
|
||||
/** @var FaultAttachmentService */
|
||||
private $attachmentService;
|
||||
|
||||
public function __construct(
|
||||
FaultManagerService $faultManagerService,
|
||||
FaultAttachmentService $attachmentService
|
||||
) {
|
||||
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
$this->attachmentService = $attachmentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$type = $request->getAttribute('type', 'file');
|
||||
@@ -54,21 +41,22 @@ class FaultAttachmentAction extends AbstractCrudAction
|
||||
try {
|
||||
/** @var UploadedFileInterface[] $files */
|
||||
$files = $request->getUploadedFiles()['file'];
|
||||
return new JsonCorsResponse(
|
||||
return new JsonResponse(
|
||||
$this->attachmentService->createAttachments($faultId, $files, $token->uid, $type),
|
||||
201
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return Response
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
$attachment = $this->attachmentService->get($id);
|
||||
@@ -89,16 +77,4 @@ class FaultAttachmentAction extends AbstractCrudAction
|
||||
// ->withHeader('Content-disposition', 'attachment;filename='.$attachment->getFileName())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -10,6 +10,6 @@ class FaultCommentFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultCommentAction($faultManagerService);
|
||||
return new FaultCommentHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
38
src/App/Handler/Fault/FaultCommentHandler.php
Normal file
38
src/App/Handler/Fault/FaultCommentHandler.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FaultCommentHandler extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->addFaultComment($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -10,6 +10,6 @@ class FaultFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultAction($faultManagerService);
|
||||
return new FaultHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
97
src/App/Handler/Fault/FaultHandler.php
Normal file
97
src/App/Handler/Fault/FaultHandler.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FaultHandler extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->faultManagerService->getFaultList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single fault
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
return new JsonResponse($this->faultManagerService->getFault($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
$token = $request->getAttribute('token');
|
||||
return new JsonResponse($this->faultManagerService->createFault($data, $token->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$token = $request->getAttribute('token');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->updateFault($id, $data, $token->uid));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a fault report (NYI)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function delete(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
return new JsonResponse($this->faultManagerService->deleteFault($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -10,6 +10,6 @@ class FaultRejectFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultRejectAction($faultManagerService);
|
||||
return new FaultRejectHandler($faultManagerService);
|
||||
}
|
||||
}
|
||||
38
src/App/Handler/Fault/FaultRejectHandler.php
Normal file
38
src/App/Handler/Fault/FaultRejectHandler.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class FaultRejectHandler extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->rejectFault($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/Fault/X_FaultS2ConfirmAction.php
Normal file
37
src/App/Handler/Fault/X_FaultS2ConfirmAction.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS2ConfirmAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->confirmFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/Fault/X_FaultS3AcknowledgeAction.php
Normal file
37
src/App/Handler/Fault/X_FaultS3AcknowledgeAction.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS3AcknowledgeAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->ackFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/Fault/X_FaultS4RepairedAction.php
Normal file
37
src/App/Handler/Fault/X_FaultS4RepairedAction.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS4RepairedAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->repairFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/App/Handler/Fault/X_FaultS5AcceptedAction.php
Normal file
36
src/App/Handler/Fault/X_FaultS5AcceptedAction.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\Fault;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class X_FaultS5AcceptedAction extends CrudHandler
|
||||
{
|
||||
/** @var FaultManagerService */
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->faultManagerService->acceptFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -9,13 +9,13 @@ class MaintenanceFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return MaintenanceAction
|
||||
* @return MaintenanceHandler
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new MaintenanceAction($maintenanceManagerService);
|
||||
return new MaintenanceHandler($maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
59
src/App/Handler/MaintenanceHandler.php
Normal file
59
src/App/Handler/MaintenanceHandler.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class MaintenanceHandler extends CrudHandler
|
||||
{
|
||||
/** @var MaintenanceManagerService */
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->maintenanceManagerService->getMaintenanceList()->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
return new JsonResponse($this->maintenanceManagerService->get($hash));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
$data = $this->getRequestData($request);
|
||||
$jwt = $request->getAttribute('token');
|
||||
return new JsonResponse($this->maintenanceManagerService->update($hash, $data, $jwt->uid));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -9,13 +9,13 @@ class MaintenanceUpcomingFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return MaintenanceUpcomingAction
|
||||
* @return MaintenanceUpcomingHandler
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new MaintenanceUpcomingAction($maintenanceManagerService);
|
||||
return new MaintenanceUpcomingHandler($maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/MaintenanceUpcomingHandler.php
Normal file
31
src/App/Handler/MaintenanceUpcomingHandler.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class MaintenanceUpcomingHandler extends CrudHandler
|
||||
{
|
||||
/** @var MaintenanceManagerService */
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->maintenanceManagerService->getUpcomingMaintenanceList()->getValues());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
@@ -10,7 +10,7 @@ class GenerateMaintenanceSheetFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return GenerateMaintenanceSheetAction
|
||||
* @return GenerateMaintenanceSheetHandler
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -20,6 +20,6 @@ class GenerateMaintenanceSheetFactory
|
||||
$pdfService = $container->get(PdfService::class);
|
||||
/** @var MaintenanceManagerService $maintenanceManagerService */
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new GenerateMaintenanceSheetAction($pdfService, $maintenanceManagerService);
|
||||
return new GenerateMaintenanceSheetHandler($pdfService, $maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use App\Service\PdfService;
|
||||
@@ -14,6 +14,6 @@ class GenerateWorksheetFactory
|
||||
$pdfService = $container->get(PdfService::class);
|
||||
/** @var FaultManagerService $faultManager */
|
||||
$faultManager = $container->get(FaultManagerService::class);
|
||||
return new GenerateWorksheetAction($pdfService, $faultManager);
|
||||
return new GenerateWorksheetHandler($pdfService, $faultManager);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
namespace App\Handler\Pdf;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\FaultManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateWorksheetAction extends AbstractCrudAction
|
||||
class GenerateWorksheetHandler extends CrudHandler
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var PdfService
|
||||
*/
|
||||
/** @var PdfService */
|
||||
private $pdfService;
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
/** @var FaultManagerService */
|
||||
private $faultManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, FaultManagerService $faultManagerService)
|
||||
@@ -34,12 +25,10 @@ class GenerateWorksheetAction extends AbstractCrudAction
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
try {
|
||||
@@ -52,16 +41,4 @@ class GenerateWorksheetAction extends AbstractCrudAction
|
||||
return new TextResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
18
src/App/Handler/PingHandler.php
Normal file
18
src/App/Handler/PingHandler.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PingHandler implements RequestHandlerInterface
|
||||
{
|
||||
public function handle(ServerRequestInterface $request) : ResponseInterface
|
||||
{
|
||||
return new JsonResponse(['ack' => time()]);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
namespace App\Handler;
|
||||
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -11,6 +11,6 @@ class SolutionTimeIntervalFactory
|
||||
{
|
||||
/** @var SolutionTimeIntervalService $facilityLocationService */
|
||||
$facilityLocationService = $container->get(SolutionTimeIntervalService::class);
|
||||
return new SolutionTimeIntervalAction($facilityLocationService);
|
||||
return new SolutionTimeIntervalHandler($facilityLocationService);
|
||||
}
|
||||
}
|
||||
31
src/App/Handler/SolutionTimeIntervalHandler.php
Normal file
31
src/App/Handler/SolutionTimeIntervalHandler.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class SolutionTimeIntervalHandler extends CrudHandler
|
||||
{
|
||||
/** @var SolutionTimeIntervalService */
|
||||
private $solutionTimeIntervalService;
|
||||
|
||||
public function __construct(SolutionTimeIntervalService $facilityLocationService)
|
||||
{
|
||||
$this->solutionTimeIntervalService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return new JsonResponse($this->solutionTimeIntervalService->getList());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Handler\User;
|
||||
|
||||
use App\Service\UserService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -11,6 +11,6 @@ class PasswordFactory
|
||||
{
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new PasswordAction($userService);
|
||||
return new PasswordHandler($userService);
|
||||
}
|
||||
}
|
||||
37
src/App/Handler/User/PasswordHandler.php
Normal file
37
src/App/Handler/User/PasswordHandler.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\User;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\UserService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PasswordHandler extends CrudHandler
|
||||
{
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function create(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$token = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->userService->changePassword($token->uid, $data['old'], $data['new']));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
namespace App\Handler\User;
|
||||
|
||||
use App\Service\UserService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
@@ -11,6 +11,6 @@ class UserFactory
|
||||
{
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new UserAction($userService);
|
||||
return new UserHandler($userService);
|
||||
}
|
||||
}
|
||||
70
src/App/Handler/User/UserHandler.php
Normal file
70
src/App/Handler/User/UserHandler.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Handler\User;
|
||||
|
||||
use ApiLibs\AbstractHandler\CrudHandler;
|
||||
use App\Service\UserService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class UserHandler extends CrudHandler
|
||||
{
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
try {
|
||||
return new JsonResponse($this->userService->getList());
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function get(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
return new JsonResponse($this->userService->get($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function update(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonResponse($this->userService->update($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,40 +3,30 @@
|
||||
namespace App\Middleware;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Tuupola\Middleware\Cors;
|
||||
use Tuupola\Middleware\CorsMiddleware;
|
||||
|
||||
class CorsMiddlewareFactory
|
||||
{
|
||||
const CORS_ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Match',
|
||||
'If-Modified-Since',
|
||||
'If-Unmodified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function __invoke(ContainerInterface $container): Cors
|
||||
public function __invoke(ContainerInterface $container): CorsMiddleware
|
||||
{
|
||||
return new Cors([
|
||||
return new CorsMiddleware([
|
||||
"origin" => ["*"],
|
||||
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
"headers.allow" => [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Match',
|
||||
'If-Modified-Since',
|
||||
'If-Unmodified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
],
|
||||
"headers.allow" => self::CORS_ALLOW_HEADERS,
|
||||
"headers.expose" => ["Etag"],
|
||||
"credentials" => true,
|
||||
// "cache" => 86400
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Middleware\JwtAuthentication;
|
||||
use Tuupola\Middleware\JwtAuthentication;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Expressive\Application;
|
||||
use Zend\Expressive\Router\Route;
|
||||
|
||||
@@ -15,9 +14,7 @@ class JwtAuthenticationFactory
|
||||
{
|
||||
const DEFAULT_HMAC = 'thisShouldBeChangedForReal';
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
/** @var Config */
|
||||
private $config;
|
||||
|
||||
public function __invoke(ContainerInterface $container): JwtAuthentication
|
||||
@@ -27,16 +24,16 @@ class JwtAuthenticationFactory
|
||||
return new JwtAuthentication([
|
||||
"secret" => $this->config->get('hmac_key', self::DEFAULT_HMAC),
|
||||
"path" => "/api",
|
||||
"passthrough" => $this->getPassThroughRoutes($container),
|
||||
"ignore" => $this->getPassThroughRoutes($container),
|
||||
"secure" => true,
|
||||
"relaxed" => [
|
||||
"localhost",
|
||||
"wnapi.yvan.hu",
|
||||
],
|
||||
"error" => function (RequestInterface $request, ResponseInterface $response, $arguments) {
|
||||
"error" => function (ResponseInterface $response, $arguments) {
|
||||
$data["status"] = "error";
|
||||
$data["message"] = $arguments["message"];
|
||||
return new JsonCorsResponse($data, 401);
|
||||
return new JsonResponse($data, 401);
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Expressive\Router\RouteResult;
|
||||
use Zend\Permissions\Rbac\Rbac;
|
||||
|
||||
class RouteAuthorization
|
||||
class RouteAuthorization implements MiddlewareInterface
|
||||
{
|
||||
|
||||
private $config;
|
||||
@@ -25,10 +27,17 @@ class RouteAuthorization
|
||||
$this->aclService = $aclService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
/**
|
||||
* Process an incoming server request and return a response, optionally delegating
|
||||
* response creation to a handler.
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if ($request->getMethod() == 'OPTIONS') {
|
||||
return $next($request, $response);
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
/** @var RouteResult $routeResult */
|
||||
@@ -36,10 +45,10 @@ class RouteAuthorization
|
||||
$token = $request->getAttribute('token');
|
||||
|
||||
if ($this->hasRouteAccess($routeResult->getMatchedRouteName(), $token->roles ?? [])) {
|
||||
return $next($request, $response);
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
return new JsonCorsResponse([
|
||||
return new JsonResponse([
|
||||
'status' => 'err',
|
||||
'message' => "Access denied to " . $routeResult->getMatchedRouteName(),
|
||||
], 401);
|
||||
@@ -72,4 +81,5 @@ class RouteAuthorization
|
||||
{
|
||||
return $this->aclService->isGranted($role, $routeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace App\Middleware;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Permissions\Rbac\Rbac;
|
||||
|
||||
class RouteAuthorizationFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container): RouteAuthorization
|
||||
public function __invoke(ContainerInterface $container): MiddlewareInterface
|
||||
{
|
||||
/** @var Config $config */
|
||||
$config = new Config($container->get('config')['acl_config']);
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Response;
|
||||
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class JsonCorsResponse extends JsonResponse
|
||||
{
|
||||
const ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
$data,
|
||||
$status = 200,
|
||||
array $headers = [],
|
||||
$encodingOptions = self::DEFAULT_JSON_FLAGS
|
||||
) {
|
||||
$headers['Access-Control-Allow-Origin'] = '*';
|
||||
$headers['Access-Control-Allow-Methods'] = 'OPTIONS,GET,POST,PUT,PATCH,DELETE';
|
||||
$headers['Access-Control-Allow-Headers'] = implode(",", self::ALLOW_HEADERS);
|
||||
parent::__construct($data, $status, $headers, $encodingOptions);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,6 @@ class FaultManagerService
|
||||
MailerService $mailer,
|
||||
UserService $userService
|
||||
) {
|
||||
|
||||
$this->em = $em;
|
||||
$this->hydrator = $hydrator;
|
||||
$this->authService = $authService;
|
||||
@@ -64,6 +63,9 @@ class FaultManagerService
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Fault|null
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function getFault(int $id): ?Fault
|
||||
{
|
||||
@@ -72,6 +74,14 @@ class FaultManagerService
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function createFault($data, $uid): Fault
|
||||
{
|
||||
/** @var User $user */
|
||||
@@ -100,6 +110,9 @@ class FaultManagerService
|
||||
* @param array $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function updateFault(int $id, array $data, int $uid): Fault
|
||||
{
|
||||
@@ -174,6 +187,15 @@ class FaultManagerService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function addFaultComment(int $id, $data, int $uid): Fault
|
||||
{
|
||||
/** @var Fault $fault */
|
||||
@@ -195,6 +217,9 @@ class FaultManagerService
|
||||
* @param $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function rejectFault(int $id, $data, int $uid): Fault
|
||||
{
|
||||
@@ -224,6 +249,8 @@ class FaultManagerService
|
||||
* @param User $user
|
||||
* @param $newState
|
||||
* @param string $comment
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
private function snapshotHandler(Fault $fault, User $user, $newState, $comment = '')
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user