Completed
Pull Request — master (#255)
by korelstar
02:24
created

SettingsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getUID() 0 3 1
A set() 0 7 1
A get() 0 3 1
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