Skip to content

Commit

Permalink
Applied the core changes to the controllers to make them work.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanbaidan committed Feb 11, 2024
1 parent c58572c commit fe4bd9e
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 121 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"ext-json": "*",
"ext-pdo": "*",
"doctrine/doctrine-orm-module": "^5.1",
Expand Down
33 changes: 22 additions & 11 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiDeliveriesModelsController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiDeliveriesModelsController::class),
],
],
],
Expand All @@ -228,7 +229,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiQuestionsController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiQuestionsController::class),
],
],
],
Expand All @@ -241,7 +243,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiQuestionsChoicesController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiQuestionsChoicesController::class),
],
],
],
Expand All @@ -254,7 +257,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiGuidesController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiGuidesController::class),
],
],
],
Expand All @@ -267,7 +271,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiGuidesItemsController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiGuidesItemsController::class),
],
],
],
Expand All @@ -293,7 +298,8 @@
'id' => '[a-f0-9-]*',
],
'defaults' => [
'controller' => Controller\ApiReferentialsController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiReferentialsController::class),
],
],
],
Expand All @@ -306,7 +312,8 @@
'id' => '[a-f0-9-]*',
],
'defaults' => [
'controller' => Controller\ApiMeasuresController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiMeasuresController::class),
],
],
],
Expand All @@ -319,7 +326,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiMeasureMeasureController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiMeasureMeasureController::class),
],
],
],
Expand Down Expand Up @@ -401,7 +409,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiRolfRisksController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiRolfRisksController::class),
],
],
],
Expand All @@ -414,7 +423,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiRolfTagsController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiRolfTagsController::class),
],
],
],
Expand All @@ -440,7 +450,8 @@
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ApiSoaCategoryController::class,
'controller' => PipeSpec::class,
'middleware' => new PipeSpec(Controller\ApiSoaCategoryController::class),
],
],
],
Expand Down
6 changes: 5 additions & 1 deletion src/Controller/ApiAnrInstancesConsequencesController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);
/**
* @link https://github.com/monarc-project for the canonical source repository
* @copyright Copyright (c) 2016-2023 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
* @copyright Copyright (c) 2016-2024 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
* @license MONARC is licensed under GNU Affero General Public License version 3
*/

Expand Down Expand Up @@ -29,6 +29,10 @@ public function __construct(
$this->patchConsequenceDataInputValidator = $patchConsequenceDataInputValidator;
}

/**
* The patch endpoint is called only when hide/show consequence action is performed.
* Possible data params: $data['isHidden'] = 0|1
*/
public function patch($id, $data)
{
/** @var Anr $anr */
Expand Down
12 changes: 11 additions & 1 deletion src/Controller/ApiAnrInstancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function get($id)
}

/**
* Instantiation of an object to the analysis.
*
* @param array $data
*/
public function create($data)
Expand All @@ -78,6 +80,8 @@ public function create($data)
}

/**
* Is called when instances consequences are set (edit impact).
*
* @param array $data
*/
public function update($id, $data)
Expand All @@ -92,6 +96,9 @@ public function update($id, $data)
return $this->getSuccessfulJsonResponse();
}

/**
* Is called when we move (drag-n-drop) instance inside of analysis.
*/
public function patch($id, $data)
{
/** @var Anr $anr */
Expand All @@ -106,7 +113,10 @@ public function patch($id, $data)

public function delete($id)
{
$this->instanceService->delete((int)$id);
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

$this->instanceService->delete($anr, (int)$id);

return $this->getSuccessfulJsonResponse();
}
Expand Down
30 changes: 26 additions & 4 deletions src/Controller/ApiAnrInstancesRisksOpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,42 @@
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Model\Entity\Anr;
use Monarc\Core\Service\InstanceRiskOpService;
use Monarc\Core\Validator\InputValidator\InstanceRiskOp\PatchInstanceRiskOpDataInputValidator;
use Monarc\Core\Validator\InputValidator\InstanceRiskOp\UpdateInstanceRiskOpDataInputValidator;

class ApiAnrInstancesRisksOpController extends AbstractRestfulControllerRequestHandler
{
use ControllerRequestResponseHandlerTrait;

private InstanceRiskOpService $instanceRiskOpService;
private PatchInstanceRiskOpDataInputValidator $patchInstanceRiskOpDataInputValidator;
private UpdateInstanceRiskOpDataInputValidator $updateInstanceRiskOpDataInputValidator;

public function __construct(InstanceRiskOpService $instanceRiskOpService)
{
public function __construct(
InstanceRiskOpService $instanceRiskOpService,
UpdateInstanceRiskOpDataInputValidator $updateInstanceRiskOpDataInputValidator,
PatchInstanceRiskOpDataInputValidator $patchInstanceRiskOpDataInputValidator
) {
$this->instanceRiskOpService = $instanceRiskOpService;
$this->updateInstanceRiskOpDataInputValidator = $updateInstanceRiskOpDataInputValidator;
$this->patchInstanceRiskOpDataInputValidator = $patchInstanceRiskOpDataInputValidator;
}

/**
* @param array $data
*/
public function update($id, $data)
{
$this->validatePostParams($this->updateInstanceRiskOpDataInputValidator, $data);
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

/** @var array $data */
$instanceRiskOp = $this->instanceRiskOpService->update($anr, (int)$id, $data);
$instanceRiskOp = $this->instanceRiskOpService->update(
$anr,
(int)$id,
$this->updateInstanceRiskOpDataInputValidator->getValidData()
);

return $this->getPreparedJsonResponse([
'cacheBrutRisk' => $instanceRiskOp->getCacheBrutRisk(),
Expand All @@ -40,10 +57,15 @@ public function update($id, $data)

public function patch($id, $data)
{
$this->validatePostParams($this->patchInstanceRiskOpDataInputValidator, $data);
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

$instanceRiskOp = $this->instanceRiskOpService->updateScaleValue($anr, (int)$id, $data);
$instanceRiskOp = $this->instanceRiskOpService->updateScaleValue(
$anr,
(int)$id,
$this->patchInstanceRiskOpDataInputValidator->getValidData()
);

return $this->getPreparedJsonResponse([
'cacheBrutRisk' => $instanceRiskOp->getCacheBrutRisk(),
Expand Down
24 changes: 8 additions & 16 deletions src/Controller/ApiAnrRisksOpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ public function __construct(InstanceRiskOpService $instanceRiskOpService)
}

/**
* @param int $id Instance ID.
* @param int|null $id Instance ID.
*/
public function get($id)
{
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');
$params = $this->parseParams();
$id = $id === null ? null : (int)$id;

$risks = $this->instanceRiskOpService->getOperationalRisks($anr, (int)$id, $params);

Expand All @@ -42,28 +43,19 @@ public function get($id)

public function getList()
{
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');
$params = $this->parseParams();

$risks = $this->instanceRiskOpService->getOperationalRisks($anr, null, $params);

return $this->getPreparedJsonResponse([
'count' => \count($risks),
'oprisks' => \array_slice($risks, ($params['page'] - 1) * $params['limit'], $params['limit']),
]);
return $this->get(null);
}

protected function parseParams(): array
{
$params = $this->params();

return [
'keywords' => $params->fromQuery("keywords"),
'kindOfMeasure' => $params->fromQuery("kindOfMeasure"),
'order' => $params->fromQuery("order", "maxRisk"),
'order_direction' => $params->fromQuery("order_direction", "desc"),
'thresholds' => $params->fromQuery("thresholds"),
'keywords' => $params->fromQuery('keywords'),
'kindOfMeasure' => $params->fromQuery('kindOfMeasure'),
'order' => $params->fromQuery('order', 'maxRisk'),
'order_direction' => $params->fromQuery('order_direction', 'desc'),
'thresholds' => $params->fromQuery('thresholds'),
'page' => (int)$params->fromQuery('page', 1),
'limit' => (int)$params->fromQuery('limit', 50),
];
Expand Down
28 changes: 13 additions & 15 deletions src/Controller/ApiAnrScalesController.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
<?php declare(strict_types=1);
/**
* @link https://github.com/monarc-project for the canonical source repository
* @copyright Copyright (c) 2016-2023 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
* @copyright Copyright (c) 2016-2024 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
* @license MONARC is licensed under GNU Affero General Public License version 3
*/

namespace Monarc\BackOffice\Controller;

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\InputFormatter\Scale\GetScalesInputFormatter;
use Monarc\Core\Model\Entity\Anr;
use Monarc\Core\Service\ScaleService;
use Monarc\Core\Validator\InputValidator\Scale\UpdateScalesDataInputValidator;

class ApiAnrScalesController extends AbstractRestfulControllerRequestHandler
{
use ControllerRequestResponseHandlerTrait;

private ScaleService $scaleService;

private GetScalesInputFormatter $getScalesInputFormatter;

public function __construct(ScaleService $scaleService, GetScalesInputFormatter $getScalesInputFormatter)
{
$this->scaleService = $scaleService;
$this->getScalesInputFormatter = $getScalesInputFormatter;
public function __construct(
private ScaleService $scaleService,
private UpdateScalesDataInputValidator $updateScalesDataInputValidator
) {
}

public function getList()
{
$formattedParams = $this->getFormattedInputParams($this->getScalesInputFormatter);
$scales = $this->scaleService->getList($formattedParams);
/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

$scales = $this->scaleService->getList($anr);

return $this->getPreparedJsonResponse([
'count' => \count($scales),
Expand All @@ -40,11 +38,11 @@ public function getList()

public function update($id, $data)
{
$this->validatePostParams($this->updateScalesDataInputValidator, $data);

/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');

/** @var array $data */
$this->scaleService->update($anr, (int)$id, $data);
$this->scaleService->update($anr, (int)$id, $this->updateScalesDataInputValidator->getValidData());

return $this->getSuccessfulJsonResponse();
}
Expand Down
Loading

0 comments on commit fe4bd9e

Please sign in to comment.