Skip to content

Commit d149555

Browse files
committed
Changed the measures links controller to the new code.
1 parent 31094b0 commit d149555

File tree

2 files changed

+24
-46
lines changed

2 files changed

+24
-46
lines changed

config/module.config.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@
326326
'id' => '[0-9]+',
327327
],
328328
'defaults' => [
329-
'controller' => PipeSpec::class,
330-
'middleware' => new PipeSpec(Controller\ApiMeasureMeasureController::class),
329+
'controller' => Controller\ApiMeasureMeasureController::class,
331330
],
332331
],
333332
],
+23-44
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,52 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* @link https://github.com/monarc-project for the canonical source repository
4-
* @copyright Copyright (c) 2016-2019 SMILE GIE Securitymadein.lu - Licensed under GNU Affero GPL v3
4+
* @copyright Copyright (c) 2016-2024 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
55
* @license MONARC is licensed under GNU Affero General Public License version 3
66
*/
77

88
namespace Monarc\BackOffice\Controller;
99

10-
use Monarc\Core\Controller\AbstractController;
10+
use Laminas\Mvc\Controller\AbstractRestfulController;
1111
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
1212
use Monarc\Core\Service\MeasureMeasureService;
1313

14-
/**
15-
* TODO: extend AbstractRestfulController and remove AbstractController.
16-
*/
17-
class ApiMeasureMeasureController extends AbstractController
14+
class ApiMeasureMeasureController extends AbstractRestfulController
1815
{
1916
use ControllerRequestResponseHandlerTrait;
2017

21-
protected $name = 'MeasureMeasure';
22-
protected $dependencies = ['father', 'child'];
23-
24-
public function __construct(MeasureMeasureService $measureMeasureService)
18+
public function __construct(private MeasureMeasureService $measureMeasureService)
2519
{
26-
parent::__construct($measureMeasureService);
2720
}
2821

2922
public function getList()
3023
{
31-
$page = $this->params()->fromQuery('page');
32-
$limit = $this->params()->fromQuery('limit');
33-
$order = $this->params()->fromQuery('order');
34-
$filter = $this->params()->fromQuery('filter');
35-
$fatherId = $this->params()->fromQuery('fatherId');
36-
$childId = $this->params()->fromQuery('childId');
37-
$filterAnd = [];
24+
/* Fetches all the measures links. */
25+
$measuresLinksData = $this->measureMeasureService->getList();
3826

39-
if ($fatherId) {
40-
$filterAnd['father'] = $fatherId;
41-
}
42-
if ($childId) {
43-
$filterAnd['child'] = $childId;
44-
}
45-
46-
$service = $this->getService();
27+
return $this->getPreparedJsonResponse([
28+
'count' => \count($measuresLinksData),
29+
'measuresLinks' => $measuresLinksData,
30+
]);
31+
}
4732

48-
$entities = $service->getList($page, $limit, $order, $filter, $filterAnd);
49-
if (count($this->dependencies)) {
50-
foreach ($entities as $key => $entity) {
51-
$this->formatDependencies($entities[$key], $this->dependencies);
52-
}
33+
public function create($data)
34+
{
35+
if ($this->isBatchData($data)) {
36+
$this->measureMeasureService->createList($data);
37+
} else {
38+
$this->measureMeasureService->create($data);
5339
}
5440

55-
return $this->getPreparedJsonResponse([
56-
'count' => $service->getFilteredCount($filter, $filterAnd),
57-
$this->name => $entities,
58-
]);
41+
return $this->getSuccessfulJsonResponse();
5942
}
6043

6144
public function deleteList($data)
6245
{
63-
if ($data === null) {
64-
$fatherId = $this->params()->fromQuery('father');
65-
$childId = $this->params()->fromQuery('child');
66-
$this->getService()->delete(['father' => $fatherId, 'child' => $childId]);
67-
68-
return $this->getSuccessfulJsonResponse();
69-
}
46+
$masterMeasureUuid = $this->params()->fromQuery('masterMeasureUuid');
47+
$linkedMeasureUuid = $this->params()->fromQuery('linkedMeasureUuid');
48+
$this->measureMeasureService->delete($masterMeasureUuid, $linkedMeasureUuid);
7049

71-
return parent::deleteList($data);
50+
return $this->getSuccessfulJsonResponse();
7251
}
7352
}

0 commit comments

Comments
 (0)