SettingsController::getSettingsAdmin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * Bookmarks_FullTextSearch - Indexing bookmarks
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\Bookmarks_FullTextSearch\Controller;
32
33
34
use Exception;
35
use OCA\Bookmarks_FullTextSearch\AppInfo\Application;
36
use OCA\Bookmarks_FullTextSearch\Service\ConfigService;
37
use OCA\Bookmarks_FullTextSearch\Service\MiscService;
38
use OCA\Bookmarks_FullTextSearch\Service\SettingsService;
39
use OCP\AppFramework\Controller;
40
use OCP\AppFramework\Http;
41
use OCP\AppFramework\Http\DataResponse;
42
use OCP\IRequest;
43
44
45
class SettingsController extends Controller {
46
47
48
	/** @var ConfigService */
49
	private $configService;
50
51
	/** @var SettingsService */
52
	private $settingsService;
53
54
	/** @var MiscService */
55
	private $miscService;
56
57
58
	/**
59
	 * SettingsController constructor.
60
	 *
61
	 * @param IRequest $request
62
	 * @param ConfigService $configService
63
	 * @param SettingsService $settingsService
64
	 * @param MiscService $miscService
65
	 */
66
	public function __construct(
67
		IRequest $request, ConfigService $configService, SettingsService $settingsService,
68
		MiscService $miscService
69
	) {
70
		parent::__construct(Application::APP_NAME, $request);
71
		$this->configService = $configService;
72
		$this->settingsService = $settingsService;
73
		$this->miscService = $miscService;
74
	}
75
76
77
	/**
78
	 * @return DataResponse
79
	 * @throws Exception
80
	 */
81
	public function getSettingsAdmin(): DataResponse {
82
		$data = $this->configService->getConfig();
83
84
		return new DataResponse($data, Http::STATUS_OK);
85
	}
86
87
88
	/**
89
	 * @param array $data
90
	 *
91
	 * @return DataResponse
92
	 * @throws Exception
93
	 */
94
	public function setSettingsAdmin(array $data): DataResponse {
95
96
		if ($this->settingsService->checkConfig($data)) {
97
			$this->configService->setConfig($data);
98
		}
99
100
		return $this->getSettingsAdmin();
101
	}
102
103
104
}
105