|
1 |
| -<?php |
| 1 | +<?php declare(strict_types=1); |
2 | 2 | /**
|
3 | 3 | * @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 |
5 | 5 | * @license MONARC is licensed under GNU Affero General Public License version 3
|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | namespace Monarc\BackOffice\Controller;
|
9 | 9 |
|
10 |
| -use Monarc\Core\Controller\AbstractController; |
| 10 | +use Laminas\Mvc\Controller\AbstractRestfulController; |
11 | 11 | use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
|
12 | 12 | use Monarc\Core\Service\MeasureMeasureService;
|
13 | 13 |
|
14 |
| -/** |
15 |
| - * TODO: extend AbstractRestfulController and remove AbstractController. |
16 |
| - */ |
17 |
| -class ApiMeasureMeasureController extends AbstractController |
| 14 | +class ApiMeasureMeasureController extends AbstractRestfulController |
18 | 15 | {
|
19 | 16 | use ControllerRequestResponseHandlerTrait;
|
20 | 17 |
|
21 |
| - protected $name = 'MeasureMeasure'; |
22 |
| - protected $dependencies = ['father', 'child']; |
23 |
| - |
24 |
| - public function __construct(MeasureMeasureService $measureMeasureService) |
| 18 | + public function __construct(private MeasureMeasureService $measureMeasureService) |
25 | 19 | {
|
26 |
| - parent::__construct($measureMeasureService); |
27 | 20 | }
|
28 | 21 |
|
29 | 22 | public function getList()
|
30 | 23 | {
|
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(); |
38 | 26 |
|
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 | + } |
47 | 32 |
|
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); |
53 | 39 | }
|
54 | 40 |
|
55 |
| - return $this->getPreparedJsonResponse([ |
56 |
| - 'count' => $service->getFilteredCount($filter, $filterAnd), |
57 |
| - $this->name => $entities, |
58 |
| - ]); |
| 41 | + return $this->getSuccessfulJsonResponse(); |
59 | 42 | }
|
60 | 43 |
|
61 | 44 | public function deleteList($data)
|
62 | 45 | {
|
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); |
70 | 49 |
|
71 |
| - return parent::deleteList($data); |
| 50 | + return $this->getSuccessfulJsonResponse(); |
72 | 51 | }
|
73 | 52 | }
|
0 commit comments