|
1 | 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-2023 Luxembourg House of Cybersecurity LHC.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\FrontOffice\Export\Controller;
|
9 | 9 |
|
10 | 10 | use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
|
11 |
| -use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; |
12 | 11 | use Monarc\FrontOffice\Entity\Anr;
|
13 |
| -use Monarc\FrontOffice\Export\Service\AnrObjectExportService; |
| 12 | +use Monarc\FrontOffice\Export\Controller\Traits\ExportResponseControllerTrait; |
| 13 | +use Monarc\FrontOffice\Export\Service\ObjectExportService; |
14 | 14 |
|
15 | 15 | class ApiAnrObjectsExportController extends AbstractRestfulControllerRequestHandler
|
16 | 16 | {
|
17 |
| - use ControllerRequestResponseHandlerTrait; |
| 17 | + use ExportResponseControllerTrait; |
18 | 18 |
|
19 |
| - private AnrObjectExportService $anrObjectExportService; |
20 |
| - |
21 |
| - public function __construct(AnrObjectExportService $anrObjectExportService) |
| 19 | + public function __construct(private ObjectExportService $anrObjectExportService) |
22 | 20 | {
|
23 |
| - $this->anrObjectExportService = $anrObjectExportService; |
24 | 21 | }
|
25 | 22 |
|
26 | 23 | /**
|
27 | 24 | * @param array $data
|
28 | 25 | */
|
29 | 26 | public function create($data)
|
30 | 27 | {
|
31 |
| - // TODO: add a validator. |
32 |
| - if (empty($data['id'])) { |
33 |
| - throw new \Monarc\Core\Exception\Exception('Object to export is required', 412); |
34 |
| - } |
35 |
| - |
36 | 28 | /** @var Anr $anr */
|
37 | 29 | $anr = $this->getRequest()->getAttribute('anr');
|
| 30 | + $result = $this->anrObjectExportService->export($anr, $data); |
38 | 31 |
|
39 |
| - // TODO: ... |
40 |
| - $data['anr'] = $anr->getId(); |
41 |
| - $output = $this->anrObjectExportService->export($anr, $data); |
42 |
| - |
43 |
| - $response = $this->getResponse(); |
44 |
| - $response->setContent($output); |
45 |
| - |
46 |
| - $headers = $response->getHeaders(); |
47 |
| - $filename = empty($data['filename']) ? $data['id'] : $data['filename']; |
48 |
| - $headers->clearHeaders() |
49 |
| - ->addHeaderLine('Content-Type', 'application/json; charset=utf-8') |
50 |
| - ->addHeaderLine('Content-Disposition', 'attachment; filename="' . $filename . '.json"'); |
51 |
| - |
52 |
| - return $response; |
| 32 | + return $this->prepareExportResponse($result['filename'], $result['content'], !empty($data['password'])); |
53 | 33 | }
|
54 | 34 | }
|
0 commit comments