Skip to content

Commit

Permalink
Fixed the risks lists action in the controller, simplified fetching s…
Browse files Browse the repository at this point in the history
…cales types.
  • Loading branch information
ruslanbaidan committed Feb 16, 2024
1 parent fe4bd9e commit 2e511a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
19 changes: 5 additions & 14 deletions src/Controller/ApiAnrRisksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ public function __construct(InstanceRiskService $instanceRiskService)
$this->instanceRiskService = $instanceRiskService;
}

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

$risks = $this->instanceRiskService->getInstanceRisks($anr, (int)$id, $params);
$risks = $this->instanceRiskService->getInstanceRisks($anr, $id === null ? null : (int)$id, $params);

return $this->getPreparedJsonResponse([
'count' => \count($risks),
Expand All @@ -41,19 +44,7 @@ public function get($id)

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

$params = $this->prepareParams();

$risks = $this->instanceRiskService->getInstanceRisks($anr, null, $params);

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

protected function prepareParams(): array
Expand Down
3 changes: 1 addition & 2 deletions src/Controller/ApiAnrRisksOpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ 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);
$risks = $this->instanceRiskOpService->getOperationalRisks($anr, $id === null ? null : (int)$id, $params);

return $this->getPreparedJsonResponse([
'count' => \count($risks),
Expand Down
15 changes: 5 additions & 10 deletions src/Controller/ApiAnrScalesTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\InputFormatter\ScaleImpactType\GetScaleImpactTypesInputFormatter;
use Monarc\Core\Model\Entity\Anr;
use Monarc\Core\Service\ScaleImpactTypeService;

Expand All @@ -19,21 +18,17 @@ class ApiAnrScalesTypesController extends AbstractRestfulControllerRequestHandle

private ScaleImpactTypeService $scaleImpactTypeService;

private GetScaleImpactTypesInputFormatter $getScaleImpactTypesInputFormatter;

public function __construct(
ScaleImpactTypeService $scaleImpactTypeService,
GetScaleImpactTypesInputFormatter $getScaleImpactTypesInputFormatter
) {
public function __construct(ScaleImpactTypeService $scaleImpactTypeService)
{
$this->scaleImpactTypeService = $scaleImpactTypeService;
$this->getScaleImpactTypesInputFormatter = $getScaleImpactTypesInputFormatter;
}

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

$scaleImpactTypesList = $this->scaleImpactTypeService->getList($formattedParams);
$scaleImpactTypesList = $this->scaleImpactTypeService->getList($anr);

return $this->getPreparedJsonResponse([
'count' => \count($scaleImpactTypesList),
Expand Down

0 comments on commit 2e511a4

Please sign in to comment.