Completed
Push — master ( 8c2cb3...b136e5 )
by korelstar
02:38
created

SettingsController::getUID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace OCA\Notes\Controller;
3
use OCP\AppFramework\Controller;
4
5
use OCP\IConfig;
6
use OCP\IRequest;
7
use OCP\IUserManager;
8
use OCP\IUserSession;
9
use OCP\Files\IRootFolder;
10
use OCP\AppFramework\Http\JSONResponse;
11
use OCA\Notes\Service\SettingsService;
12
13
class SettingsController extends Controller
14
{
15
	private $service;
16
	private $userSession;
17
18
	public function __construct(
19
		$appName,
20
		IRequest $request,
21
		SettingsService $service,
22
		IUserSession $userSession
23
	) {
24
		parent::__construct($appName, $request);
25
		$this->service = $service;
26
		$this->userSession = $userSession;
27
	}
28
29
	private function getUID() {
30
		return $this->userSession->getUser()->getUID();
31
	}
32
33
	/**
34
	 * @NoAdminRequired
35
	 * @throws \OCP\PreConditionNotMetException
36
	 */
37
	public function set() {
38
		$this->service->set(
39
			$this->getUID(),
40
			$this->request->getParams()
41
		);
42
		return $this->get();
43
	}
44
45
	/**
46
	 * @NoAdminRequired
47
	 */
48
	public function get() {
49
		return new JSONResponse($this->service->getAll($this->getUID()));
50
	}
51
}
52